當前位置: 首頁>>代碼示例>>Python>>正文


Python options.log_file_prefix方法代碼示例

本文整理匯總了Python中tornado.options.log_file_prefix方法的典型用法代碼示例。如果您正苦於以下問題:Python options.log_file_prefix方法的具體用法?Python options.log_file_prefix怎麽用?Python options.log_file_prefix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.options的用法示例。


在下文中一共展示了options.log_file_prefix方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: enable_pretty_logging

# 需要導入模塊: from tornado import options [as 別名]
# 或者: from tornado.options import log_file_prefix [as 別名]
def enable_pretty_logging():
    """Turns on formatted logging output as configured."""
    if (options.log_to_stderr or
        (options.log_to_stderr is None and not options.log_file_prefix)):
        # Set up color if we are in a tty and curses is installed
        color = False
        if curses and sys.stderr.isatty():
            try:
                curses.setupterm()
                if curses.tigetnum("colors") > 0:
                    color = True
            except:
                pass
        channel = logging.StreamHandler()
        channel.setFormatter(_LogFormatter(color=color))
        logging.getLogger().addHandler(channel)

    if options.log_file_prefix:
        channel = logging.handlers.RotatingFileHandler(
            filename=options.log_file_prefix,
            maxBytes=options.log_file_max_size,
            backupCount=options.log_file_num_backups)
        channel.setFormatter(_LogFormatter(color=False))
        logging.getLogger().addHandler(channel) 
開發者ID:omererdem,項目名稱:honeything,代碼行數:26,代碼來源:options.py

示例2: parse_logger_callback

# 需要導入模塊: from tornado import options [as 別名]
# 或者: from tornado.options import log_file_prefix [as 別名]
def parse_logger_callback(self):
        if options.disable_log:
            options.logging = None
        if options.log_file_prefix and options.log_port_prefix:
            options.log_file_prefix += ".%s" % options.port
        if options.log_patch:
            logging.handlers.TimedRotatingFileHandler = ProcessLogTimedFileHandler
        tornado_logger = logging.getLogger('tornado')
        enable_pretty_logging(logger=tornado_logger)
        logdir = options.logging_dir or settings.LOGGING_DIR
        for log in settings.LOGGING:
            opt = OptionParser()
            define_logging_options(opt)
            self.define(opt)
            opt.log_rotate_when = log.get('when', 'midnight')
            opt.log_to_stderr = log.get('log_to_stderr', False) if options.log_to_stderr is None else options.log_to_stderr
            opt.logging = log.get('level', 'INFO')
            opt.log_file_prefix = os.path.join(logdir, log['filename'])
            if log.get('backups'):
                opt.log_file_num_backups = log.get('backups')
            if opt.log_port_prefix:
                opt.log_file_prefix += ".%s" % options.port
            opt.log_rotate_interval = log.get('interval', 1)
            opt.log_rotate_mode = 'time'
            logger = logging.getLogger(log['name'])
            logger.propagate = 0
            enable_pretty_logging(options=opt, logger=logger)
            map(lambda h: h.setFormatter(LogFormatter(fmt=log.get("formatter", LogFormatter.DEFAULT_FORMAT),
                                                      color=settings.DEBUG)), logger.handlers) 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:31,代碼來源:webserver.py

示例3: enable_pretty_logging

# 需要導入模塊: from tornado import options [as 別名]
# 或者: from tornado.options import log_file_prefix [as 別名]
def enable_pretty_logging(options=None, logger=None):
    """Turns on formatted logging output as configured.

    This is called automatically by `tornado.options.parse_command_line`
    and `tornado.options.parse_config_file`.
    """
    if options is None:
        import tornado.options
        options = tornado.options.options
    if options.logging is None or options.logging.lower() == 'none':
        return
    if logger is None:
        logger = logging.getLogger()
    logger.setLevel(getattr(logging, options.logging.upper()))
    if options.log_file_prefix:
        rotate_mode = options.log_rotate_mode
        if rotate_mode == 'size':
            channel = logging.handlers.RotatingFileHandler(
                filename=options.log_file_prefix,
                maxBytes=options.log_file_max_size,
                backupCount=options.log_file_num_backups)
        elif rotate_mode == 'time':
            channel = logging.handlers.TimedRotatingFileHandler(
                filename=options.log_file_prefix,
                when=options.log_rotate_when,
                interval=options.log_rotate_interval,
                backupCount=options.log_file_num_backups)
        else:
            error_message = 'The value of log_rotate_mode option should be ' +\
                            '"size" or "time", not "%s".' % rotate_mode
            raise ValueError(error_message)
        channel.setFormatter(LogFormatter(color=False))
        logger.addHandler(channel)

    if (options.log_to_stderr or
            (options.log_to_stderr is None and not logger.handlers)):
        # Set up color if we are in a tty and curses is installed
        channel = logging.StreamHandler()
        channel.setFormatter(LogFormatter())
        logger.addHandler(channel) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:42,代碼來源:log.py

示例4: define_logging_options

# 需要導入模塊: from tornado import options [as 別名]
# 或者: from tornado.options import log_file_prefix [as 別名]
def define_logging_options(options=None):
    """Add logging-related flags to ``options``.

    These options are present automatically on the default options instance;
    this method is only necessary if you have created your own `.OptionParser`.

    .. versionadded:: 4.2
        This function existed in prior versions but was broken and undocumented until 4.2.
    """
    if options is None:
        # late import to prevent cycle
        import tornado.options
        options = tornado.options.options
    options.define("logging", default="info",
                   help=("Set the Python log level. If 'none', tornado won't touch the "
                         "logging configuration."),
                   metavar="debug|info|warning|error|none")
    options.define("log_to_stderr", type=bool, default=None,
                   help=("Send log output to stderr (colorized if possible). "
                         "By default use stderr if --log_file_prefix is not set and "
                         "no other logging is configured."))
    options.define("log_file_prefix", type=str, default=None, metavar="PATH",
                   help=("Path prefix for log files. "
                         "Note that if you are running multiple tornado processes, "
                         "log_file_prefix must be different for each of them (e.g. "
                         "include the port number)"))
    options.define("log_file_max_size", type=int, default=100 * 1000 * 1000,
                   help="max size of log files before rollover")
    options.define("log_file_num_backups", type=int, default=10,
                   help="number of log files to keep")

    options.define("log_rotate_when", type=str, default='midnight',
                   help=("specify the type of TimedRotatingFileHandler interval "
                         "other options:('S', 'M', 'H', 'D', 'W0'-'W6')"))
    options.define("log_rotate_interval", type=int, default=1,
                   help="The interval value of timed rotating")

    options.define("log_rotate_mode", type=str, default='size',
                   help="The mode of rotating files(time or size)")

    options.add_parse_callback(lambda: enable_pretty_logging(options)) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:43,代碼來源:log.py

示例5: enable_pretty_logging

# 需要導入模塊: from tornado import options [as 別名]
# 或者: from tornado.options import log_file_prefix [as 別名]
def enable_pretty_logging(options=options):
    """Turns on formatted logging output as configured.

    This is called automatically by `parse_command_line`.
    """
    root_logger = logging.getLogger()
    if options.log_file_prefix:
        channel = logging.handlers.RotatingFileHandler(
            filename=options.log_file_prefix,
            maxBytes=options.log_file_max_size,
            backupCount=options.log_file_num_backups)
        channel.setFormatter(_LogFormatter(color=False))
        root_logger.addHandler(channel)

    if (options.log_to_stderr or
        (options.log_to_stderr is None and not root_logger.handlers)):
        # Set up color if we are in a tty and curses is installed
        color = False
        if curses and sys.stderr.isatty():
            try:
                curses.setupterm()
                if curses.tigetnum("colors") > 0:
                    color = True
            except Exception:
                pass
        channel = logging.StreamHandler()
        channel.setFormatter(_LogFormatter(color=color))
        root_logger.addHandler(channel) 
開發者ID:omererdem,項目名稱:honeything,代碼行數:30,代碼來源:options.py

示例6: enable_pretty_logging

# 需要導入模塊: from tornado import options [as 別名]
# 或者: from tornado.options import log_file_prefix [as 別名]
def enable_pretty_logging(options: Any = None, logger: logging.Logger = None) -> None:
    """Turns on formatted logging output as configured.

    This is called automatically by `tornado.options.parse_command_line`
    and `tornado.options.parse_config_file`.
    """
    if options is None:
        import tornado.options

        options = tornado.options.options
    if options.logging is None or options.logging.lower() == "none":
        return
    if logger is None:
        logger = logging.getLogger()
    logger.setLevel(getattr(logging, options.logging.upper()))
    if options.log_file_prefix:
        rotate_mode = options.log_rotate_mode
        if rotate_mode == "size":
            channel = logging.handlers.RotatingFileHandler(
                filename=options.log_file_prefix,
                maxBytes=options.log_file_max_size,
                backupCount=options.log_file_num_backups,
                encoding="utf-8",
            )  # type: logging.Handler
        elif rotate_mode == "time":
            channel = logging.handlers.TimedRotatingFileHandler(
                filename=options.log_file_prefix,
                when=options.log_rotate_when,
                interval=options.log_rotate_interval,
                backupCount=options.log_file_num_backups,
                encoding="utf-8",
            )
        else:
            error_message = (
                "The value of log_rotate_mode option should be "
                + '"size" or "time", not "%s".' % rotate_mode
            )
            raise ValueError(error_message)
        channel.setFormatter(LogFormatter(color=False))
        logger.addHandler(channel)

    if options.log_to_stderr or (options.log_to_stderr is None and not logger.handlers):
        # Set up color if we are in a tty and curses is installed
        channel = logging.StreamHandler()
        channel.setFormatter(LogFormatter())
        logger.addHandler(channel) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:48,代碼來源:log.py

示例7: run_start

# 需要導入模塊: from tornado import options [as 別名]
# 或者: from tornado.options import log_file_prefix [as 別名]
def run_start(name: str,
              description: str,
              version: str,
              application_factory: ApplicationFactory,
              log_file_prefix: str = None,
              args: List[str] = None) -> int:
    """
    Run the WebAPI command-line interface.

    :param name: The service name.
    :param description: The CLI's description.
    :param version: The CLI's version string.
    :param application_factory: A no-arg function that creates a Tornado web application instance.
    :param log_file_prefix: Log file prefix name.
    :param args: The command-line arguments, may be None.
    :return: the exit code, zero on success.
    """
    if args is None:
        args = sys.argv[1:]

    parser = _get_common_cli_parser(name, description, version)
    parser.add_argument('--file', '-f', dest='file', metavar='FILE',
                        help="write service information to FILE")
    parser.add_argument('--auto-stop-after', '-s', dest='auto_stop_after', metavar='AUTO_STOP_AFTER', type=float,
                        help="stop service after AUTO_STOP_AFTER seconds of inactivity")
    parser.add_argument('--verbose', '-v', dest='verbose', action='store_true',
                        help="delegate log output to the console (stderr)")

    args_obj = parser.parse_args(args)

    try:
        if not os.path.isdir(os.path.dirname(log_file_prefix)):
            os.makedirs(os.path.dirname(log_file_prefix), exist_ok=True)

        service = WebAPI()
        service.start(name, application_factory,
                      log_file_prefix=log_file_prefix,
                      log_to_stderr=args_obj.verbose,
                      port=args_obj.port,
                      address=args_obj.address,
                      caller=args_obj.caller,
                      user_root_path=args_obj.user_root_path,
                      service_info_file=args_obj.file,
                      auto_stop_after=args_obj.auto_stop_after)

        return 0
    except Exception as e:
        if args_obj.print_traceback:
            import traceback
            traceback.print_exc()
        print('error: %s' % e)
        return 1 
開發者ID:CCI-Tools,項目名稱:cate,代碼行數:54,代碼來源:webapi.py


注:本文中的tornado.options.log_file_prefix方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。