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


Python handlers.WatchedFileHandler方法代碼示例

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


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

示例1: _get_logger

# 需要導入模塊: from logging import handlers [as 別名]
# 或者: from logging.handlers import WatchedFileHandler [as 別名]
def _get_logger(name=settings.logger_filename()):
    logger = logging.getLogger(name)

    if not logger.handlers:

        logger.setLevel(logging.INFO)

        # create formatter and handler
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        path = settings.logger_file()
        handler = WatchedFileHandler(path)
        # combine
        handler.setLevel(logging.INFO)
        handler.setFormatter(formatter)
        logger.addHandler(handler)

    return logger 
開發者ID:Tribler,項目名稱:Dollynator,代碼行數:19,代碼來源:logger.py

示例2: register_loggers

# 需要導入模塊: from logging import handlers [as 別名]
# 或者: from logging.handlers import WatchedFileHandler [as 別名]
def register_loggers(app):
    if app.debug:
        return

    import logging
    from logging.handlers import WatchedFileHandler
    import sys

    logfile = app.config['DOORMAN_LOGGING_FILENAME']
    if logfile == '-':
        handler = logging.StreamHandler(sys.stdout)
    else:
        handler = WatchedFileHandler(logfile)
    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:mwielgoszewski,項目名稱:doorman,代碼行數:22,代碼來源:application.py

示例3: get_logger

# 需要導入模塊: from logging import handlers [as 別名]
# 或者: from logging.handlers import WatchedFileHandler [as 別名]
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:faucetsdn,項目名稱:faucet,代碼行數:27,代碼來源:valve_util.py

示例4: add_file_handler

# 需要導入模塊: from logging import handlers [as 別名]
# 或者: from logging.handlers import WatchedFileHandler [as 別名]
def add_file_handler(self, log_file):
        """
        Create, format & add the handler that will log to the log file
        """
        handler = WatchedFileHandler(log_file)
        handler.setLevel(self.logger.level)
        formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s', "%Y-%m-%d %H:%M:%S")
        handler.setFormatter(formatter)
        self.logger.addHandler(handler) 
開發者ID:NVISO-BE,項目名稱:ee-outliers,代碼行數:11,代碼來源:logging.py

示例5: set_logger

# 需要導入模塊: from logging import handlers [as 別名]
# 或者: from logging.handlers import WatchedFileHandler [as 別名]
def set_logger(target='std'):
    global logger
    for h in logger.handlers[:]:
        logger.removeHandler(h)
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter('\n%(asctime)s - %(name)s - %(levelname)s - \n%(message)s\n')
    if target == 'std':
        handler = logging.StreamHandler(sys.stdout)
    else:
        handler = WatchedFileHandler(target)
    handler.setFormatter(formatter)
    handler.setLevel(logging.DEBUG)
    logger.addHandler(handler) 
開發者ID:nokia,項目名稱:SROS-grpc-services,代碼行數:15,代碼來源:grpc_shell.py

示例6: _setup_logger

# 需要導入模塊: from logging import handlers [as 別名]
# 或者: from logging.handlers import WatchedFileHandler [as 別名]
def _setup_logger(self, level, log_file):
        """Setup log level and log file if set"""
        if not level:
            return
        if logger.handlers:
            return
        if hasattr(logging, 'NullHandler'):
            logger.addHandler(logging.NullHandler())
        formatter = logging.Formatter(
            '[%(levelname)s] %(asctime)s - %(module)s.%(funcName)s() '
            '- %(message)s')
        level = getattr(logging, level.upper())
        logger.setLevel(level)
        handler = logging.StreamHandler()
        logger.addHandler(handler)
        handler.setFormatter(formatter)
        if not log_file:
            return
        try:
            _handler = WatchedFileHandler(log_file)
        except IOError:
            logger.error("Could not write to %s, falling back to stdout",
                         log_file)
        else:
            logger.addHandler(_handler)
            _handler.setFormatter(formatter) 
開發者ID:InfluxGraph,項目名稱:influxgraph,代碼行數:28,代碼來源:finder.py

示例7: get_logger

# 需要導入模塊: from logging import handlers [as 別名]
# 或者: from logging.handlers import WatchedFileHandler [as 別名]
def get_logger(self, name):
        logger = logging.getLogger(name)

        if not logger.handlers:
            logger.setLevel(logging.INFO)

            # create formatter and handler
            formatter = logging.Formatter('%(asctime)s;%(message)s')
            handler = WatchedFileHandler(os.path.join(log_file_path, name))
            # combine
            handler.setLevel(logging.INFO)
            handler.setFormatter(formatter)
            logger.addHandler(handler)

        return logger 
開發者ID:Tribler,項目名稱:Dollynator,代碼行數:17,代碼來源:tracker_bot.py

示例8: set_logger

# 需要導入模塊: from logging import handlers [as 別名]
# 或者: from logging.handlers import WatchedFileHandler [as 別名]
def set_logger(debug=False, logfile=None):

    logFormatter = \
            logging.Formatter("%(asctime)s %(levelname)s %(process)d %(filename)s:%(funcName)s:%(lineno)d %(message)s")
    rootLogger = logging.getLogger()

    if debug:
        logging.level = logging.DEBUG
        rootLogger.setLevel(logging.DEBUG)
    else:
        logging.level = logging.INFO
        rootLogger.setLevel(logging.INFO)

    if logfile:
        try:
            logdir = os.path.dirname(logfile)
            if logdir and not os.path.isdir(logdir):
                os.makedirs(logdir)
            fileHandler = WatchedFileHandler(logfile)
            fileHandler.setFormatter(logFormatter)
            rootLogger.addHandler(fileHandler)
        except Exception as e:
            pass

    consoleHandler = logging.StreamHandler()
    consoleHandler.setFormatter(logFormatter)
    rootLogger.addHandler(consoleHandler) 
開發者ID:ansible,項目名稱:ansibullbot,代碼行數:29,代碼來源:logs.py

示例9: setup_logger

# 需要導入模塊: from logging import handlers [as 別名]
# 或者: from logging.handlers import WatchedFileHandler [as 別名]
def setup_logger(log_file: str, log_level: int = logging.INFO) -> logging.Logger:
    root = logging.getLogger()
    logging.basicConfig(level=log_level)
    handler = WatchedFileHandler(log_file)
    formatter = logging.Formatter("%(asctime)s;%(levelname)s;%(message)s", "%Y-%m-%d %H:%M:%S %z")
    handler.setFormatter(formatter)
    root.addHandler(handler)
    root.addHandler(TimedRotatingFileHandler(log_file, when="d", interval=1, backupCount=100)) 
開發者ID:bbedward,項目名稱:graham_discord_bot,代碼行數:10,代碼來源:logger.py

示例10: get_logger

# 需要導入模塊: from logging import handlers [as 別名]
# 或者: from logging.handlers import WatchedFileHandler [as 別名]
def get_logger():
    logger = logging.getLogger("dpow")
    logging.basicConfig(level=logging.INFO)
    log_file = "/tmp/dpow.txt"
    formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(filename)s@%(funcName)s:%(lineno)s", "%Y-%m-%d %H:%M:%S %z")
    handler = WatchedFileHandler(log_file)
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    logger.addHandler(TimedRotatingFileHandler(log_file, when="d", interval=1, backupCount=100))
    return logger 
開發者ID:guilhermelawless,項目名稱:nano-dpow,代碼行數:12,代碼來源:logger.py

示例11: init_app

# 需要導入模塊: from logging import handlers [as 別名]
# 或者: from logging.handlers import WatchedFileHandler [as 別名]
def init_app():
    """ Initialize the main application instance and return it"""
    async def close_redis(app):
        """Close redis connections"""
        log.server_logger.info('Closing redis connections')
        app['rdata'].close()

    async def open_redis(app):
        """Open redis connections"""
        log.server_logger.info("Opening redis connections")
        app['rdata'] = await aioredis.create_redis_pool((redis_host, redis_port),
                                                db=int(os.getenv('REDIS_DB', '2')), encoding='utf-8', minsize=2, maxsize=15)
        # Global vars
        app['clients'] = {} # Keep track of connected clients
        app['last_msg'] = {} # Last time a client has sent a message
        app['active_messages'] = set() # Avoid duplicate messages from being processes simultaneously
        app['cur_prefs'] = {} # Client currency preferences
        app['subscriptions'] = {} # Store subscription UUIDs, this is used for targeting callback accounts
        app['active_work'] = set() # Keep track of active work requests to prevent duplicates

    # Setup logger
    if debug_mode:
        logging.basicConfig(level=logging.DEBUG)
    else:
        root = logging.getLogger('aiohttp.server')
        logging.basicConfig(level=logging.INFO)
        if options.log_to_stdout:
            handler = logging.StreamHandler(sys.stdout)
            formatter = logging.Formatter("%(asctime)s;%(levelname)s;%(message)s", "%Y-%m-%d %H:%M:%S %z")
            handler.setFormatter(formatter)
            root.addHandler(handler)
        else:
            handler = WatchedFileHandler(log_file)
            formatter = logging.Formatter("%(asctime)s;%(levelname)s;%(message)s", "%Y-%m-%d %H:%M:%S %z")
            handler.setFormatter(formatter)
            root.addHandler(handler)
            root.addHandler(TimedRotatingFileHandler(log_file, when="d", interval=1, backupCount=100))        

    app = web.Application()
    cors = aiohttp_cors.setup(app, defaults={
        "*": aiohttp_cors.ResourceOptions(
                allow_credentials=True,
                expose_headers="*",
                allow_headers="*",
            )
    })    
    app.add_routes([web.get('/', websocket_handler)]) # All WS requests
    app.add_routes([web.post('/callback', callback)]) # HTTP Callback from node
    # HTTP API
    users_resource = cors.add(app.router.add_resource("/api"))
    cors.add(users_resource.add_route("POST", http_api))    
    #app.add_routes([web.post('/callback', callback)])
    app.on_startup.append(open_redis)
    app.on_shutdown.append(close_redis)

    return app 
開發者ID:appditto,項目名稱:natrium-wallet-server,代碼行數:58,代碼來源:natriumcast.py

示例12: init

# 需要導入模塊: from logging import handlers [as 別名]
# 或者: from logging.handlers import WatchedFileHandler [as 別名]
def init(self, *priv):
        if not priv:
            raise SnmpfwdError('Bad log file params, need filename')
        if sys.platform[:3] == 'win':
            # fix possibly corrupted absolute windows path
            if len(priv[0]) == 1 and priv[0].isalpha() and len(priv) > 1:
                priv = [priv[0] + ':' + priv[1]] + list(priv[2:])

        maxsize = 0
        maxage = None
        if len(priv) > 1 and priv[1]:
            try:
                if priv[1][-1] == 'k':
                    maxsize = int(priv[1][:-1]) * 1024
                elif priv[1][-1] == 'm':
                    maxsize = int(priv[1][:-1]) * 1024 * 1024
                elif priv[1][-1] == 'g':
                    maxsize = int(priv[1][:-1]) * 1024 * 1024 * 1024
                elif priv[1][-1] == 'S':
                    maxage = ('S', int(priv[1][:-1]))
                elif priv[1][-1] == 'M':
                    maxage = ('M', int(priv[1][:-1]))
                elif priv[1][-1] == 'H':
                    maxage = ('H', int(priv[1][:-1]))
                elif priv[1][-1] == 'D':
                    maxage = ('D', int(priv[1][:-1]))
                else:
                    raise ValueError('Unknown log rotation criterion: %s' % priv[1][-1])

            except ValueError:
                raise SnmpfwdError(
                    'Error in timed log rotation specification. Use <NNN>k,m,g '
                    'for size or <NNN>S,M,H,D for time limits'
                )

        try:
            if maxsize:
                handler = handlers.RotatingFileHandler(priv[0], backupCount=30, maxBytes=maxsize)
            elif maxage:
                handler = self.TimedRotatingFileHandler(priv[0], backupCount=30, when=maxage[0], interval=maxage[1])
            else:
                handler = handlers.WatchedFileHandler(priv[0])

        except Exception:
            raise SnmpfwdError(
                'Failure configure logging: %s' % sys.exc_info()[1]
            )

        handler.setFormatter(logging.Formatter('%(message)s'))

        self._logger.addHandler(handler)

        self('Log file %s, rotation rules: %s' % (priv[0], maxsize and '> %sKB' % (maxsize/1024) or maxage and '%s%s' % (maxage[1], maxage[0]) or '<none>')) 
開發者ID:etingof,項目名稱:snmpfwd,代碼行數:55,代碼來源:log.py


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