当前位置: 首页>>代码示例>>Python>>正文


Python WatchedFileHandler.setLevel方法代码示例

本文整理汇总了Python中logging.handlers.WatchedFileHandler.setLevel方法的典型用法代码示例。如果您正苦于以下问题:Python WatchedFileHandler.setLevel方法的具体用法?Python WatchedFileHandler.setLevel怎么用?Python WatchedFileHandler.setLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在logging.handlers.WatchedFileHandler的用法示例。


在下文中一共展示了WatchedFileHandler.setLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getLogger

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
def getLogger(name, level=logging.INFO, handlers=[]):
	logger = logging.getLogger(name)

	if len(handlers) != 0:
		logger.setLevel(level)

	if "console" in handlers:
		strm = StreamHandler()
		fmt = logging.Formatter('%(message)s')
		strm.setLevel(level)
		strm.setFormatter(fmt)
		logger.addHandler(strm)

	if "file" in handlers:
		conf = handlers['file']
		fl = WatchedFileHandler(conf['logfile'])
		fl.setLevel(level)

		fmt = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
		fl.setFormatter(fmt)
		logger.addHandler(fl)

	if "syslog" in handlers:
		sysl = SysLogHandler(address='/dev/log', facility=SysLogHandler.LOG_SYSLOG)
		sysl.setLevel(level)

		formatter = logging.Formatter('%(name)s[' + str(os.getpid()) + '] %(levelname)-8s: %(message)s')
		sysl.setFormatter(formatter)
		logger.addHandler(sysl)

	return logger
开发者ID:LordGaav,项目名称:imagecat,代码行数:33,代码来源:__init__.py

示例2: create_app

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
def create_app():
    from server.views.frontend import frontend as blueprint_frontend
    from server.views.entry import entry as blueprint_entry
    from server.views.filter import filter as blueprint_filter
    from server.views.pinboard import pinboard as blueprint_pinboard
    from server.db import db
    from server.login import login_manager

    app = Flask(__name__, instance_relative_config=True)
    app.jinja_options = dict(app.jinja_options)
    app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension')

    app.config.from_pyfile("default_settings.py")
    app.config.from_envvar('PINBOARD_SETTINGS', silent=True)

    if not app.debug:
        file_handler = WatchedFileHandler(app.config.get("LOG_FILENAME",
            "pinboard.log"))
        file_handler.setLevel(logging.WARNING)
        app.logger.addHandler(file_handler)

    assets = Environment(app)

    js_assets = Bundle(
            "scripts/jquery-1.7.2.js",
            "scripts/jquery-ui-1.8.16.custom.min.js",
            #"scripts/chosen.jquery.min.js",
            "scripts/bootstrap.min.js",
            "scripts/angular-1.0.1.js",
            #"scripts/angular-cookies-1.0.0.js",
            #"scripts/taffy.js",
            "scripts/sugar-1.2.4.min.js",
            #"scripts/jquery.couch.js",
            Bundle("lib/*.coffee", filters=["coffeescript", ]),
            filters=["rjsmin", ],
            output="generated_app.js",
            )
    css_assets = Bundle(
            "stylesheets/jquery-ui-1.8.16.custom.css",
            Bundle(
                "stylesheets/app.less",
                filters=["less", ],
                ),
            filters=["cssmin", ],
            output="generated_app.css",
            )
    assets.register('js_all', js_assets)
    assets.register('css_all', css_assets)

    db.init_app(app)
    login_manager.setup_app(app)

    app.register_blueprint(blueprint_frontend)
    app.register_blueprint(blueprint_entry, url_prefix="/entry")
    app.register_blueprint(blueprint_filter, url_prefix="/filter")
    app.register_blueprint(blueprint_pinboard, url_prefix="/pinboards")

    return app
开发者ID:weltenwort,项目名称:dd4epinboard,代码行数:60,代码来源:__init__.py

示例3: _logger

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
def _logger(level, out_stream, name=None, log_file=None,
            log_file_level=logging.DEBUG, milliseconds=False):
    """Create the actual logger instance, logging at the given level

    if name is None, it will get args[0] without the extension (e.g. gina).
    'out_stream must be passed, the recommended value is sys.stderr'
    """
    if name is None:
        # Determine the logger name from the script name
        name = sys.argv[0]
        name = re.sub('.py[oc]?$', '', name)

    # We install our custom handlers and formatters on the root logger.
    # This means that if the root logger is used, we still get correct
    # formatting. The root logger should probably not be used.
    root_logger = logging.getLogger()

    # reset state of root logger
    reset_root_logger()

    # Make it print output in a standard format, suitable for
    # both command line tools and cron jobs (command line tools often end
    # up being run from inside cron, so this is a good thing).
    hdlr = logging.StreamHandler(out_stream)
    # We set the level on the handler rather than the logger, so other
    # handlers with different levels can be added for things like debug
    # logs.
    root_logger.setLevel(0)
    hdlr.setLevel(level)
    if milliseconds:
        # Python default datefmt includes milliseconds.
        formatter = LaunchpadFormatter(datefmt=None)
    else:
        # Launchpad default datefmt does not include milliseconds.
        formatter = LaunchpadFormatter()
    hdlr.setFormatter(formatter)
    root_logger.addHandler(hdlr)

    # Add an optional aditional log file.
    if log_file is not None:
        handler = WatchedFileHandler(log_file, encoding="UTF8")
        handler.setFormatter(formatter)
        handler.setLevel(log_file_level)
        root_logger.addHandler(handler)

    # Create our logger
    logger = logging.getLogger(name)

    # Set the global log
    log._log = logger

    # Inform the user the extra log file is in operation.
    if log_file is not None:
        log.info(
            "Logging %s and higher messages to %s" % (
                logging.getLevelName(log_file_level), log_file))

    return logger
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:60,代码来源:logger.py

示例4: main

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
def main(args):
    log = logging.getLogger("addisonarches.web")
    log.setLevel(args.log_level)

    formatter = logging.Formatter(
        "%(asctime)s %(levelname)-7s %(name)s|%(message)s")
    ch = logging.StreamHandler()

    if args.log_path is None:
        ch.setLevel(args.log_level)
    else:
        fh = WatchedFileHandler(args.log_path)
        fh.setLevel(args.log_level)
        fh.setFormatter(formatter)
        log.addHandler(fh)
        ch.setLevel(logging.WARNING)

    ch.setFormatter(formatter)
    log.addHandler(ch)

    loop = asyncio.SelectorEventLoop()
    asyncio.set_event_loop(loop)

    down = asyncio.Queue(loop=loop)
    up = asyncio.Queue(loop=loop)

    #TODO: Read service name from CLI
    service = "dev"  # Cf qa, demo, prod, etc
    tok = token(args.connect, service, APP_NAME)
    node = create_udp_node(loop, tok, down, up)
    loop.create_task(node(token=tok))

    app = aiohttp.web.Application()
    assets = Assets(app, **vars(args))
    reg = Registration(app, tok, down, up, **vars(args))
    transitions = Transitions(app, **vars(args))
    work = Workflow(app, tok, down, up, **vars(args))
    for svc in (assets, reg, transitions, work):
        log.info("{0.__class__.__name__} object serves {1}".format(
            svc, ", ".join(svc.routes.keys())))

    handler = app.make_handler()
    f = loop.create_server(handler, args.host, args.port)
    srv = loop.run_until_complete(f)

    log.info("Serving on {0[0]}:{0[1]}".format(srv.sockets[0].getsockname()))
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
    finally:
        loop.run_until_complete(handler.finish_connections(1.0))
        srv.close()
        loop.run_until_complete(srv.wait_closed())
        loop.run_until_complete(app.finish())
    loop.close()
开发者ID:tundish,项目名称:addisonarches,代码行数:58,代码来源:main.py

示例5: create_logger

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
def create_logger(filename=settings.LOG_FILE, level=settings.LOG_LEVEL, name=settings.LOG_NAME):
    # WatchedFileHandler watches the file it is logging to.
    # If the file changes, it is closed and reopened using the file name.
    file_handler = WatchedFileHandler(filename)
    file_handler.setLevel(level)
    logger = logging.getLogger(name)
    logger.addHandler(file_handler)

    logger.setLevel(level)
    return logger
开发者ID:b2ence,项目名称:mythical-poc,代码行数:12,代码来源:middleware.py

示例6: main

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
def main():
    parser = argparse.ArgumentParser(description="Send out broker notifications")
    parser.add_argument("-c", "--config", dest="config",
                        help="location of the broker configuration file")
    parser.add_argument("--one_shot", action="store_true",
                        help="do just a single run and then exit")
    parser.add_argument("--debug", action="store_true",
                        help="turn on debug logs on stderr")

    opts = parser.parse_args()

    config = Config(configfile=opts.config)

    # These modules must be imported after the configuration has been
    # initialized
    from aquilon.aqdb.db_factory import DbFactory

    db = DbFactory()

    if opts.debug:
        level = logging.DEBUG
        logging.basicConfig(level=level, stream=sys.stderr,
                            format='%(asctime)s [%(levelname)s] %(message)s')
    else:
        level = logging.INFO
        logfile = os.path.join(config.get("broker", "logdir"), "aq_notifyd.log")

        handler = WatchedFileHandler(logfile)
        handler.setLevel(level)

        formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
        handler.setFormatter(formatter)

        rootlog = logging.getLogger()
        rootlog.addHandler(handler)
        rootlog.setLevel(level)

    # Apply configured log settings
    for logname, level in config.items("logging"):
        if level not in logging._levelNames:
            continue
        logging.getLogger(logname).setLevel(logging._levelNames[level])

    logger = logging.getLogger("aq_notifyd")

    if opts.one_shot:
        update_index_and_notify(config, logger, db)
    else:
        signal.signal(signal.SIGTERM, exit_handler)
        signal.signal(signal.SIGINT, exit_handler)

        run_loop(config, logger, db)
开发者ID:piojo,项目名称:aquilon,代码行数:54,代码来源:aq_notifyd.py

示例7: configure_logger

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
    def configure_logger(self):
        logger = logging.getLogger(self.name)

        logger.setLevel(logging.INFO)
        formatter = logging.Formatter('%(levelname)s %(asctime)s %(message)s')

        logname = self.logname if hasattr(self, 'logname') else '{}.log'.format(self.name)
        handler = WatchedFileHandler('{}/{}'.format(self.logging_folder, logname))
        handler.setFormatter(formatter)
        handler.setLevel(logging.INFO)

        logger.addHandler(handler)

        return logger
开发者ID:UPCnet,项目名称:maxbunny,代码行数:16,代码来源:consumer.py

示例8: main

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
def main(args):
    log = logging.getLogger(APP_NAME)
    log.setLevel(args.log_level)

    formatter = logging.Formatter(
        "%(asctime)s %(levelname)-7s %(name)s|%(message)s")
    ch = logging.StreamHandler()

    if args.log_path is None:
        ch.setLevel(args.log_level)
    else:
        fh = WatchedFileHandler(args.log_path)
        fh.setLevel(args.log_level)
        fh.setFormatter(formatter)
        log.addHandler(fh)
        ch.setLevel(logging.WARNING)

    ch.setFormatter(formatter)
    log.addHandler(ch)

    loop = asyncio.SelectorEventLoop()
    asyncio.set_event_loop(loop)

    down = asyncio.Queue(loop=loop)
    up = asyncio.Queue(loop=loop)

    tok = token(args.connect, APP_NAME)
    node = create_udp_node(loop, tok, down, up)
    loop.create_task(node(token=tok))
    loop.create_task(queue_logger(loop, up))

    msg = parcel(
        tok,
        Alert(datetime.datetime.now(), "Hello World!"),
        via=Address(tok.namespace, tok.user, tok.service, turberfield.ipc.demo.router.APP_NAME)
    )
    log.info("Sending message: {}".format(msg))
    loop.call_soon_threadsafe(functools.partial(down.put_nowait, msg))

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        for task in asyncio.Task.all_tasks(loop=loop):
            task.cancel()

        for resource in resources:
            resource.close()

    finally:
        loop.close()
开发者ID:tundish,项目名称:turberfield-ipc,代码行数:52,代码来源:sender.py

示例9: get_logger

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
def get_logger(name):
    logger = logging.getLogger(name)
    format = logging.Formatter("[%(levelname)s] %(asctime)s - %(name)s - %(message)s", datefmt="%m-%d-%Y %H:%M:%S")
    logger.propagate = False

    if PRINT_STDOUT:
        handler = logging.StreamHandler()
        handler.setLevel(LOG_LEVEL)
        handler.setFormatter(format)
        logger.addHandler(handler)

    handler = WatchedFileHandler(LOG_FILE)
    handler.setLevel(LOG_LEVEL)
    handler.setFormatter(format)
    logger.addHandler(handler)
    return logger
开发者ID:thdtjsdn,项目名称:l1j-client,代码行数:18,代码来源:update.py

示例10: init

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
def init(config_file):
	global logger
	global config
	log_file = None
	verbose = False
	n = 0
	count = len(sys.argv)
	while n < count:
		arg = sys.argv[n]
		if arg.startswith('--'):
			buf = arg[2:]
			at = buf.find('=')
			if at != -1:
				var = buf[:at]
				val = buf[at + 1:]
			else:
				var = buf
				val = None
			del sys.argv[n]
			count -= 1

			if var == 'config':
				config_file = val
			elif var == 'logfile':
				log_file = val
			elif var == 'verbose':
				verbose = True
		else:
			n += 1

	logger = logging.getLogger('app')
	if log_file:
		logger_handler = WatchedFileHandler(log_file)
	else:
		logger_handler = logging.StreamHandler(stream=sys.stdout)
	if verbose:
		logger.setLevel(logging.DEBUG)
		logger_handler.setLevel(logging.DEBUG)
	else:
		logger.setLevel(logging.INFO)
		logger_handler.setLevel(logging.INFO)
	formatter = logging.Formatter(fmt='%(levelname)s %(asctime)s.%(msecs)03d %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
	logger_handler.setFormatter(formatter)
	logger.addHandler(logger_handler)

	config = ConfigParser.ConfigParser()
	config.read([config_file])
开发者ID:fanout,项目名称:scaledemo,代码行数:49,代码来源:app.py

示例11: _create_handlers

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
def _create_handlers(filename=LOG_FILEPATH, level=LOG_LEVEL):
    formatter = logging.Formatter(format)

    # WatchedFileHandler watches the file it is logging to.
    # If the file changes, it is closed and reopened using the file name.
    file_handler = WatchedFileHandler(filename)
    file_handler.setFormatter(formatter)
    file_handler.setLevel(level)

    # Used by internal log monitoring applications
    syslog_handler = SysLogHandler(facility=LOG_LOCAL3)
    syslog_handler.setFormatter(formatter)
    syslog_handler.setLevel(level)

    global handlers
    handlers = [file_handler, syslog_handler]

    return handlers
开发者ID:bmentges,项目名称:brainiak_api,代码行数:20,代码来源:log.py

示例12: __create_producer_logger

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
 def __create_producer_logger(self, producer, info):
     self.log('Inside Server.__create_producer_logger, Producer: {0}, Info: {1}'.format(producer, info), level=logging.DEBUG)
     logger = logging.getLogger(producer)
     logger.setLevel(logging.DEBUG)
     logger.propagate = False
 
     # We'll use a WatchedFileHandler and utilize some external application to rotate the logs periodically
     logFilePath = os.path.join(settings.config['logdir'], '{0}.log'.format(producer))
     handler = WatchedFileHandler(logFilePath)
     handler.setLevel(info['logging.level'])
     formatter = logging.Formatter(fmt='%(message)s')
     handler.setFormatter(formatter)
     logger.addHandler(handler)
     
     handler = logging.StreamHandler()
     handler.setLevel(logging.DEBUG)
     formatter = logging.Formatter(fmt='%(message)s')
     handler.setFormatter(formatter)
     logger.addHandler(handler)
开发者ID:kestava,项目名称:log-server,代码行数:21,代码来源:server.py

示例13: register_loggers

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
def register_loggers(app):
    if app.debug:
        return

    import logging
    from logging.handlers import WatchedFileHandler

    log_fname = app.config['DOORMAN_LOGGING_FILENAME']
    if log_fname == 'sys.stdout':
    	handler = logging.StreamHandler(log_fname)
    else:
        handler = WatchedFileHandler(log_fname)
    levelname = app.config['DOORMAN_LOGGING_LEVEL']
    if levelname in ('DEBUG', 'INFO', 'WARN', 'WARNING', 'ERROR', 'CRITICAL'):
        handler.setLevel(getattr(logging, levelname))
    formatter = logging.Formatter(app.config['DOORMAN_LOGGING_FORMAT'])
    handler.setFormatter(formatter)

    app.logger.addHandler(handler)
开发者ID:jcorina,项目名称:doorman,代码行数:21,代码来源:application.py

示例14: init

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
    def init(cls, config):
        formatter = logging.Formatter(config.FORMAT)
        root = logging.getLogger('')
        root.setLevel(config.ROOT_LEVEL)

        if config.LOG_TO_CONSOLE:
            console_handler = logging.StreamHandler()
            console_handler.setLevel(config.CONSOLE_LEVEL)
            console_handler.setFormatter(formatter)
            root.addHandler(console_handler)
        if config.LOG_TO_FILE:
            file_name = cls.generate_log_file_name()
            file_handler = WatchedFileHandler(
                os.path.join(config.FILE_BASE, file_name),
                encoding='utf-8'
            )
            file_handler.setLevel(config.FILE_LEVEL)
            file_handler.setFormatter(formatter)
            root.addHandler(file_handler)
开发者ID:ghop02,项目名称:diving-videos,代码行数:21,代码来源:Log.py

示例15: main

# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import setLevel [as 别名]
def main(args):
    log = logging.getLogger(APP_NAME)
    log.setLevel(args.log_level)

    formatter = logging.Formatter(
        "%(asctime)s %(levelname)-7s %(name)s|%(message)s")
    ch = logging.StreamHandler()

    if args.log_path is None:
        ch.setLevel(args.log_level)
    else:
        fh = WatchedFileHandler(args.log_path)
        fh.setLevel(args.log_level)
        fh.setFormatter(formatter)
        log.addHandler(fh)
        ch.setLevel(logging.WARNING)

    ch.setFormatter(formatter)
    log.addHandler(ch)

    loop = asyncio.SelectorEventLoop()
    asyncio.set_event_loop(loop)

    down = asyncio.Queue(loop=loop)
    up = asyncio.Queue(loop=loop)

    tok = token(args.connect, APP_NAME)
    node = create_udp_node(loop, tok, down, up)
    loop.create_task(node(token=tok))

    log.info("Starting router node...")
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        for task in asyncio.Task.all_tasks(loop=loop):
            task.cancel()

        for resource in resources:
            resource.close()

    finally:
        loop.close()
开发者ID:tundish,项目名称:turberfield-ipc,代码行数:44,代码来源:router.py


注:本文中的logging.handlers.WatchedFileHandler.setLevel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。