Exemplo n.º 1
0
 def create_default_logger(cls):
     # stderr logger
     format = '%(asctime)s:%(levelname)s:%(name)s:' + cls.VERSION +\
              ':%(filename)s:%(lineno)d:%(funcName)s %(message)s'
     handler = logging.StreamHandler(cls.stderr)
     handler.setFormatter(createColoredFormatter(cls.stderr, format))
     return handler
Exemplo n.º 2
0
 def create_default_logger(klass):
     # stdout logger
     format = '%(asctime)s:%(levelname)s:%(name)s:' + klass.VERSION +\
              ':%(filename)s:%(lineno)d:%(funcName)s %(message)s'
     handler = logging.StreamHandler(sys.stdout)
     handler.setFormatter(createColoredFormatter(sys.stdout, format))
     return handler
Exemplo n.º 3
0
    def parse_args(self, args):
        self.options, args = self._parser.parse_args(args)

        if self.options.shell_completion:
            items = set()
            for option in self._parser.option_list:
                if not option.help is optparse.SUPPRESS_HELP:
                    items.update(str(option).split("/"))
            items.update(self._get_completions())
            print " ".join(items)
            sys.exit(0)

        if self.options.debug or self.options.save_responses:
            level = logging.DEBUG
        elif self.options.verbose:
            level = logging.INFO
        elif self.options.quiet:
            level = logging.ERROR
        else:
            level = logging.WARNING

        logging.root.setLevel(level)

        if self.options.save_responses:
            responses_dirname = tempfile.mkdtemp(prefix="weboob_session_")
            print "Debug data will be saved in this directory: %s" % responses_dirname
            from weboob.tools.browser import BaseBrowser

            BaseBrowser.SAVE_RESPONSES = True
            BaseBrowser.responses_dirname = responses_dirname
            self.add_logging_file_handler(os.path.join(responses_dirname, "debug.log"))

        # file logger
        if self.options.logging_file:
            self.add_logging_file_handler(self.options.logging_file)
        else:
            # stdout logger
            format = "%(asctime)s:%(levelname)s:%(name)s:%(filename)s:%(lineno)d:%(funcName)s %(message)s"
            handler = logging.StreamHandler(sys.stdout)
            handler.setFormatter(createColoredFormatter(sys.stdout, format))
            logging.root.addHandler(handler)

        self._handle_options()
        self.handle_application_options()

        return args
Exemplo n.º 4
0
def init_logging(level=logging.WARNING):
    """
    Initialize loggers.

    :param level: Minimal severity to log.
    """
    root_logger = logging.getLogger()

    root_logger.setLevel(level)

    handler = logging.StreamHandler(sys.stderr)
    fmt = ('%(asctime)s:%(levelname)s:%(name)s:%(filename)s:'
           '%(lineno)d:%(funcName)s %(message)s')
    if os.environ.get('NODE_ENV', 'production') != 'production':
        # Only output colored logging if not running in production.
        handler.setFormatter(createColoredFormatter(sys.stderr, fmt))
    else:
        handler.setFormatter(logging.Formatter(fmt))

    root_logger.addHandler(handler)
Exemplo n.º 5
0
def init_logging(level, is_prod):
    """
    Initialize loggers.

    :param level: Minimal severity to log.
    :param is_prod: whether we're running in production or not.
    """
    root_logger = logging.getLogger()

    root_logger.setLevel(level)

    handler = logging.StreamHandler(sys.stderr)
    fmt = ('%(asctime)s:%(levelname)s:%(name)s:%(filename)s:'
           '%(lineno)d:%(funcName)s %(message)s')

    # Only output colored logging if not running in production.
    if is_prod:
        handler.setFormatter(logging.Formatter(fmt))
    else:
        handler.setFormatter(createColoredFormatter(sys.stderr, fmt))

    root_logger.addHandler(handler)
Exemplo n.º 6
0
def init_logging(level, is_prod):
    """
    Initialize loggers.

    :param level: Minimal severity to log.
    :param is_prod: whether we're running in production or not.
    """
    root_logger = logging.getLogger()

    root_logger.setLevel(level)

    handler = logging.StreamHandler(sys.stderr)
    fmt = (
        '%(asctime)s:%(levelname)s:%(name)s:%(filename)s:'
        '%(lineno)d:%(funcName)s %(message)s'
    )

    # Only output colored logging if not running in production.
    if is_prod:
        handler.setFormatter(logging.Formatter(fmt))
    else:
        handler.setFormatter(createColoredFormatter(sys.stderr, fmt))

    root_logger.addHandler(handler)
Exemplo n.º 7
0
 def create_default_logger(klass):
     # stdout logger
     format = '%(asctime)s:%(levelname)s:%(name)s:%(filename)s:%(lineno)d:%(funcName)s %(message)s'
     handler = logging.StreamHandler(sys.stdout)
     handler.setFormatter(createColoredFormatter(sys.stdout, format))
     return handler