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


Python handlers.WatchedFileHandler类代码示例

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


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

示例1: __init__

 def __init__(self, application):
     self.application = application
     log_file = WatchedFileHandler(settings.API_LOG)
     log_format = logging.Formatter(LOGFORMAT, DATEFORMAT)
     log_file.setFormatter(log_format)
     api_logger.setLevel(logging.DEBUG)
     api_logger.addHandler(log_file)
开发者ID:newsky,项目名称:fuelweb,代码行数:7,代码来源:logger.py

示例2: close

    def close(self):
        self._lock.acquire(timeout=2)
        try:
            WatchedFileHandler.close(self)

        finally:
            self._lock.release()
开发者ID:jay-katta,项目名称:wok,代码行数:7,代码来源:safewatchedfilehandler.py

示例3: get_logger

def get_logger(logname, logfile, loglevel, propagate):
    """Create and return a logger object."""

    stream_handlers = {
        'STDOUT': sys.stdout,
        'STDERR': sys.stderr,
    }

    try:
        if logfile in stream_handlers:
            logger_handler = logging.StreamHandler(stream_handlers[logfile])
        else:
            logger_handler = WatchedFileHandler(logfile)
    except (PermissionError, FileNotFoundError) as err: # pytype: disable=name-error
        print(err)
        sys.exit(-1)

    logger = logging.getLogger(logname)
    log_fmt = '%(asctime)s %(name)-6s %(levelname)-8s %(message)s'
    logger_handler.setFormatter(
        logging.Formatter(log_fmt, '%b %d %H:%M:%S'))
    logger.addHandler(logger_handler)
    logger.propagate = propagate
    logger.setLevel(loglevel)
    return logger
开发者ID:anarkiwi,项目名称:faucet,代码行数:25,代码来源:valve_util.py

示例4: __init__

    def __init__(self, name):
        self.name = name

        self.plugins.register(self.name, self)

        self._methods = {}

        self.debug = bool('DEBUG-%s' % self.name in get_vim_buffers_names())

        self.log = logging.getLogger(self.name)
        self.log.setLevel(logging.DEBUG if self.debug else logging.INFO)

        self.settings.option('LOG_PATH', default=None)

        if self.settings['LOG_PATH']:
            if not os.path.exists(self.settings['LOG_PATH']):
                os.makedirs(self.settings['LOG_PATH'])

            log_file_name = '%s.log' % os.path.join(self.settings['LOG_PATH'],
                                                    self.name)

            handler = WatchedFileHandler(log_file_name, 'w')

        else:
            handler = logging.FileHandler('/dev/null')

        fm = logging.Formatter(
            '%(asctime)s %(levelname)s: %(message)s',
            '%H:%M:%S'
        )
        handler.setFormatter(fm)
        self.log.addHandler(handler)

        self.log.debug('Plugin name: %r', self.name)
开发者ID:ivanovwaltz,项目名称:vim-pythogen,代码行数:34,代码来源:pythogen.py

示例5: __init__

    def __init__(self, *args, **kwargs):
        WatchedFileHandler.__init__(self, *args, **kwargs)

        def reopenLog(signal, frame):
            """the signal handler"""
            self.reopen_stream()
        signal.signal(signal.SIGUSR1, reopenLog)
开发者ID:cloudfleet,项目名称:filesync-server,代码行数:7,代码来源:logger.py

示例6: main

def main():
    # Set up our log level
    try:
        filename = config['server.logging_filename']
        handler = WatchedFileHandler(filename)
    except KeyError:
        handler = StreamHandler()
    handler.setFormatter(logging.Formatter(config['server.logging_format']))
    root_logger = logging.getLogger('')
    root_logger.setLevel(int(config['server.logging_level']))
    root_logger.addHandler(handler)

    settings = {
    }

    if 'debug' in config:
        log.info('Enabling Tornado Web debug mode')
        settings['debug'] = config['debug']

    host = config['server.socket_host']
    port = int(config['server.socket_port'])

    application = tornado.web.Application([
        (r"/event", EventHandler),
    ], **settings)

    if config.get('dry-run'):
        log.info('In dry-run mode')

    log.info('Starting corgi server http://%s:%d/' % (host, port))
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(port, host)
    tornado.ioloop.IOLoop.instance().start()
开发者ID:glencoesoftware,项目名称:corgi,代码行数:33,代码来源:server.py

示例7: getLogger

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,代码行数:31,代码来源:__init__.py

示例8: emit

    def emit(self, record):
        self._lock.acquire(timeout=2)
        try:
            WatchedFileHandler.emit(self, record)

        finally:
            self._lock.release()
开发者ID:jay-katta,项目名称:wok,代码行数:7,代码来源:safewatchedfilehandler.py

示例9: create_app

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,代码行数:58,代码来源:__init__.py

示例10: _logger

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,代码行数:58,代码来源:logger.py

示例11: emit

 def emit(self, record):
     old_umask = os.umask(self.umask)
     try:
         # This does not work on py 2.6
         # WatchedFileHandler is probably old style class in 2.6
         # super(UmaskWatchedFileHandler, self).emit(record)
         WatchedFileHandler.emit(self, record)
     finally:
         os.umask(old_umask)
开发者ID:juhamust,项目名称:multiproject,代码行数:9,代码来源:log.py

示例12: main

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,代码行数:56,代码来源:main.py

示例13: create_logger

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,代码行数:10,代码来源:middleware.py

示例14: getDaemonLogger

def getDaemonLogger(filePath, log_format=None, loglevel=logging.INFO):
    logger = logging.getLogger()
    logger.setLevel(loglevel)
    try:
        watchedHandler = WatchedFileHandler(filePath)
    except Exception as e:  # pylint: disable=broad-except
        return e, None

    watchedHandler.setFormatter(logging.Formatter(log_format or '%(asctime)s %(msg)s'))
    logger.addHandler(watchedHandler)
    return logger, watchedHandler
开发者ID:dawei1991,项目名称:lava-dispatcher,代码行数:11,代码来源:daemonise.py

示例15: main

def main():
    if len(sys.argv) < 5:
        usage(f = sys.stderr)
        sys.exit(-1)
        
    http_ip = sys.argv[1]
    http_port = int(sys.argv[2])
    socksip = sys.argv[3]
    socksport = int(sys.argv[4])
    
    opts, _ = getopt.gnu_getopt(sys.argv[5:], "hdp:l:",
                            ["help", "debug", "pidfile=", "logfile="])
    for o, a in opts:
        if o == "-h" or o == "--help":
            usage()
            sys.exit()
        if o == "-d" or o == "--debug":
            options.logginglevel = logging.DEBUG
        elif o == "-p" or o == "--pidfile":
            options.daemonize = True
            options.pidfile = a
        elif o == "-l" or o == "--logfile":
            options.daemonize = True
            options.logfile = a
            
    if options.daemonize:
        pid = os.fork()
        if pid != 0:
            # write pidfile by father
            f = open(options.pidfile, "w")
            print >> f, pid
            f.close()
            sys.exit(0)
    
    if options.daemonize:
        logger = logging.getLogger()
        logger.setLevel(options.logginglevel)
        ch = WatchedFileHandler(options.logfile)
        ch.setFormatter(logging.Formatter('[%(asctime)s][%(name)s][%(levelname)s] - %(message)s'))
        logger.addHandler(ch)
    else:
        logging.basicConfig(
            format='[%(asctime)s][%(name)s][%(levelname)s] - %(message)s',
            datefmt='%Y-%d-%m %H:%M:%S',
            level=options.logginglevel,    
        )
    
    socks = SocksServer(socksip, socksport, SocksRelayFactory(), timeout=30, maxclient=500)
    socks.start()

    globalvars.socksip = socksip
    globalvars.socksport = socksport
    globalvars.sockstimeout = 60
    WSGIServer((http_ip, http_port), meek_server_application, log=None).serve_forever()
开发者ID:52M,项目名称:firefly-proxy,代码行数:54,代码来源:server.py


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