Python logbook.INFO Examples

The following are 18 code examples of logbook.INFO(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module logbook , or try the search function .
Example #1
Source File: logging.py    From restful-services-in-pyramid with MIT License 6 votes vote down vote up
def global_init(logfile):
    if logfile:
        logbook.TimedRotatingFileHandler(
            logfile, level=logbook.INFO, date_format='%Y-%m-%d').push_application()
    else:
        logbook.StreamHandler(sys.stdout, level=logbook.TRACE).push_application() 
Example #2
Source File: gunicorn_conf.py    From SnowAlert with Apache License 2.0 6 votes vote down vote up
def post_fork(server, worker):
    server.log.info('Worker spawned (pid: %s)', worker.pid)

    logging_rotating_file_handler = logging.handlers.RotatingFileHandler(
        config.LOG_FILE_PATH.replace('.log', f'.{worker.pid}.flask.log'),
        maxBytes=5 * 1024 * 1024,
        backupCount=5,
    )

    root_logger = logging.getLogger()
    root_logger.addHandler(logging_rotating_file_handler)
    root_logger.setLevel(logging.CRITICAL)

    logger_setup = logbook.NestedSetup(
        [
            logbook.StreamHandler(sys.stdout, level=logbook.INFO, bubble=True),
            logbook.RotatingFileHandler(
                config.LOG_FILE_PATH.replace('.log', f'.{worker.pid}.log'),
                level=logbook.INFO,
                max_size=5 * 1024 * 1024,
                bubble=True,
            ),
        ]
    )
    logger_setup.push_application() 
Example #3
Source File: bin.py    From saltyrtc-server-python with MIT License 5 votes vote down vote up
def _get_logging_level(verbosity: int) -> LogbookLevel:
    import logbook
    return LogbookLevel({
        1: logbook.CRITICAL,
        2: logbook.ERROR,
        3: logbook.WARNING,
        4: logbook.NOTICE,
        5: logbook.INFO,
        6: logbook.DEBUG,
        7: logbook.TRACE,
    }[verbosity]) 
Example #4
Source File: log.py    From code-review with Mozilla Public License 2.0 5 votes vote down vote up
def setup_papertrail(project_name, channel, PAPERTRAIL_HOST, PAPERTRAIL_PORT):
    """
    Setup papertrail account using taskcluster secrets
    """

    # Setup papertrail
    papertrail = logbook.SyslogHandler(
        application_name=f"code-review/{channel}/{project_name}",
        address=(PAPERTRAIL_HOST, int(PAPERTRAIL_PORT)),
        level=logbook.INFO,
        format_string="{record.time} {record.channel}: {record.message}",
        bubble=True,
    )
    papertrail.push_application() 
Example #5
Source File: log.py    From code-coverage with Mozilla Public License 2.0 5 votes vote down vote up
def setup_papertrail(project_name, channel, PAPERTRAIL_HOST, PAPERTRAIL_PORT):
    """
    Setup papertrail account using taskcluster secrets
    """

    # Setup papertrail
    papertrail = logbook.SyslogHandler(
        application_name=f"code-coverage/{channel}/{project_name}",
        address=(PAPERTRAIL_HOST, int(PAPERTRAIL_PORT)),
        level=logbook.INFO,
        format_string="{record.time} {record.channel}: {record.message}",
        bubble=True,
    )
    papertrail.push_application() 
Example #6
Source File: log_service.py    From cookiecutter-course with GNU General Public License v2.0 5 votes vote down vote up
def __get_logbook_logging_level(level_str):
        # logbook levels:
        # CRITICAL = 15
        # ERROR = 14
        # WARNING = 13
        # NOTICE = 12
        # INFO = 11
        # DEBUG = 10
        # TRACE = 9
        # NOTSET = 0

        level_str = level_str.upper().strip()

        if level_str == 'CRITICAL':
            return logbook.CRITICAL
        elif level_str == 'ERROR':
            return logbook.ERROR
        elif level_str == 'WARNING':
            return logbook.WARNING
        elif level_str == 'NOTICE':
            return logbook.NOTICE
        elif level_str == 'INFO':
            return logbook.INFO
        elif level_str == 'DEBUG':
            return logbook.DEBUG
        elif level_str == 'TRACE':
            return logbook.TRACE
        elif level_str == 'NOTSET':
            return logbook.NOTSET
        else:
            raise ValueError("Unknown logbook log level: {}".format(level_str)) 
Example #7
Source File: utils.py    From regipy with MIT License 5 votes vote down vote up
def _get_log_handlers(verbose):
    return [logbook.StreamHandler(sys.stdout, level=logbook.DEBUG if verbose else logbook.INFO, bubble=True)] 
Example #8
Source File: custom_logger.py    From WindAdapter with MIT License 5 votes vote down vote up
def set_level(self, log_level):
        if log_level.lower() == LogLevel.INFO:
            self.logger.level = logbook.INFO
        elif log_level.lower() == LogLevel.WARNING:
            self.logger.level = logbook.WARNING
        elif log_level.lower() == LogLevel.CRITICAL:
            self.logger.level = logbook.CRITICAL
        elif log_level.lower() == LogLevel.NOTSET:
            self.logger.level = logbook.NOTSET 
Example #9
Source File: custom_logger.py    From WindAdapter with MIT License 5 votes vote down vote up
def __init__(self,
                 log_level=LogLevel.INFO,
                 format_str='[{record.time:%Y-%m-%d %H:%M:%S}] - {record.channel} - {record.level_name} '
                            '- {record.message}'):
        self.logger = Logger('WindAdapter')
        set_datetime_format('local')
        StreamHandler(sys.stdout, format_string=format_str).push_application()
        FileHandler('WindAdapter.log', bubble=True, format_string=format_str).push_application()
        self.set_level(log_level) 
Example #10
Source File: log_service.py    From cookiecutter-pyramid-talk-python-starter with MIT License 5 votes vote down vote up
def __get_logbook_logging_level(level_str):
        # logbook levels:
        # CRITICAL = 15
        # ERROR = 14
        # WARNING = 13
        # NOTICE = 12
        # INFO = 11
        # DEBUG = 10
        # TRACE = 9
        # NOTSET = 0

        level_str = level_str.upper().strip()

        if level_str == 'CRITICAL':
            return logbook.CRITICAL
        elif level_str == 'ERROR':
            return logbook.ERROR
        elif level_str == 'WARNING':
            return logbook.WARNING
        elif level_str == 'NOTICE':
            return logbook.NOTICE
        elif level_str == 'INFO':
            return logbook.INFO
        elif level_str == 'DEBUG':
            return logbook.DEBUG
        elif level_str == 'TRACE':
            return logbook.TRACE
        elif level_str == 'NOTSET':
            return logbook.NOTSET
        else:
            raise ValueError("Unknown logbook log level: {}".format(level_str)) 
Example #11
Source File: logging.py    From restful-services-in-pyramid with MIT License 5 votes vote down vote up
def global_init(logfile):
    if logfile:
        logbook.TimedRotatingFileHandler(
            logfile, level=logbook.INFO, date_format='%Y-%m-%d').push_application()
    else:
        logbook.StreamHandler(sys.stdout, level=logbook.TRACE).push_application() 
Example #12
Source File: logging.py    From restful-services-in-pyramid with MIT License 5 votes vote down vote up
def global_init(logfile):
    if logfile:
        logbook.TimedRotatingFileHandler(
            logfile, level=logbook.INFO, date_format='%Y-%m-%d').push_application()
    else:
        logbook.StreamHandler(sys.stdout, level=logbook.TRACE).push_application() 
Example #13
Source File: logging.py    From restful-services-in-pyramid with MIT License 5 votes vote down vote up
def global_init(logfile):
    if logfile:
        logbook.TimedRotatingFileHandler(
            logfile, level=logbook.INFO, date_format='%Y-%m-%d').push_application()
    else:
        logbook.StreamHandler(sys.stdout, level=logbook.TRACE).push_application() 
Example #14
Source File: config.py    From pantalaimon with Apache License 2.0 5 votes vote down vote up
def parse_log_level(value):
    # type: (str) -> logbook
    value = value.lower()

    if value == "info":
        return logbook.INFO
    elif value == "warning":
        return logbook.WARNING
    elif value == "error":
        return logbook.ERROR
    elif value == "debug":
        return logbook.DEBUG

    return logbook.WARNING 
Example #15
Source File: log_service.py    From python-for-entrepreneurs-course-demos with MIT License 5 votes vote down vote up
def __get_logbook_logging_level(level_str):
        # logbook levels:
        # CRITICAL = 15
        # ERROR = 14
        # WARNING = 13
        # NOTICE = 12
        # INFO = 11
        # DEBUG = 10
        # TRACE = 9
        # NOTSET = 0

        level_str = level_str.upper().strip()

        if level_str == 'CRITICAL':
            return logbook.CRITICAL
        elif level_str == 'ERROR':
            return logbook.ERROR
        elif level_str == 'WARNING':
            return logbook.WARNING
        elif level_str == 'NOTICE':
            return logbook.NOTICE
        elif level_str == 'INFO':
            return logbook.INFO
        elif level_str == 'DEBUG':
            return logbook.DEBUG
        elif level_str == 'TRACE':
            return logbook.TRACE
        elif level_str == 'NOTSET':
            return logbook.NOTSET
        else:
            raise ValueError("Unknown logbook log level: {}".format(level_str)) 
Example #16
Source File: log.py    From ClusterRunner with Apache License 2.0 4 votes vote down vote up
def configure_logging(log_level=None, log_file=None, simplified_console_logs=False):
    """
    This should be called once as early as possible in app startup to configure logging handlers and formatting.

    :param log_level: The level at which to record log messages (DEBUG|INFO|NOTICE|WARNING|ERROR|CRITICAL)
    :type log_level: str
    :param log_file: The file to write logs to, or None to disable logging to a file
    :type log_file: str | None
    :param simplified_console_logs: Whether or not to use the simplified logging format and coloring
    :type simplified_console_logs: bool
    """
    # Set datetimes in log messages to be local timezone instead of UTC
    logbook.set_datetime_format('local')

    # Redirect standard lib logging to capture third-party logs in our log files (e.g., tornado, requests)
    logging.root.setLevel(logging.WARNING)  # don't include DEBUG/INFO/NOTICE-level logs from third parties
    logbook.compat.redirect_logging(set_root_logger_level=False)

    # Add a NullHandler to suppress all log messages lower than our desired log_level. (Otherwise they go to stderr.)
    NullHandler().push_application()

    log_level = log_level or Configuration['log_level']
    format_string, log_colors = _LOG_FORMAT_STRING, _LOG_COLORS
    if simplified_console_logs:
        format_string, log_colors = _SIMPLIFIED_LOG_FORMAT_STRING, _SIMPLIFIED_LOG_COLORS

    # handler for stdout
    log_handler = _ColorizingStreamHandler(
        stream=sys.stdout,
        level=log_level,
        format_string=format_string,
        log_colors=log_colors,
        bubble=True,
    )
    log_handler.push_application()

    # handler for log file
    if log_file:
        fs.create_dir(os.path.dirname(log_file))
        previous_log_file_exists = os.path.exists(log_file)

        event_handler = _ColorizingRotatingFileHandler(
            filename=log_file,
            level=log_level,
            format_string=_LOG_FORMAT_STRING,
            log_colors=_LOG_COLORS,
            bubble=True,
            max_size=Configuration['max_log_file_size'],
            backup_count=Configuration['max_log_file_backups'],
        )
        event_handler.push_application()
        if previous_log_file_exists:
            # Force application to create a new log file on startup.
            event_handler.perform_rollover(increment_logfile_counter=False)
        else:
            event_handler.log_application_summary() 
Example #17
Source File: log.py    From code-coverage with Mozilla Public License 2.0 4 votes vote down vote up
def init_logger(
    project_name,
    channel=None,
    level=logbook.INFO,
    PAPERTRAIL_HOST=None,
    PAPERTRAIL_PORT=None,
    sentry_dsn=None,
):

    if not channel:
        channel = os.environ.get("APP_CHANNEL")

    # Output logs on stderr, with color support on consoles
    fmt = "{record.time} [{record.level_name:<8}] {record.channel}: {record.message}"
    handler = logbook.more.ColorizedStderrHandler(level=level, format_string=fmt)
    handler.push_application()

    # Log to papertrail
    if channel and PAPERTRAIL_HOST and PAPERTRAIL_PORT:
        setup_papertrail(project_name, channel, PAPERTRAIL_HOST, PAPERTRAIL_PORT)

    # Log to senty
    if channel and sentry_dsn:
        setup_sentry(project_name, channel, sentry_dsn)

    def logbook_factory(*args, **kwargs):
        # Logger given to structlog
        logbook.compat.redirect_logging()
        return logbook.Logger(level=level, *args, **kwargs)

    # Setup structlog over logbook, with args list at the end
    processors = [
        structlog.stdlib.PositionalArgumentsFormatter(),
        structlog.processors.StackInfoRenderer(),
        structlog.processors.format_exc_info,
        UnstructuredRenderer(),
    ]

    structlog.configure(
        context_class=structlog.threadlocal.wrap_dict(dict),
        processors=processors,
        logger_factory=logbook_factory,
        wrapper_class=structlog.stdlib.BoundLogger,
        cache_logger_on_first_use=True,
    ) 
Example #18
Source File: log.py    From code-review with Mozilla Public License 2.0 4 votes vote down vote up
def init_logger(
    project_name,
    channel=None,
    level=logbook.INFO,
    PAPERTRAIL_HOST=None,
    PAPERTRAIL_PORT=None,
    SENTRY_DSN=None,
):

    if not channel:
        channel = os.environ.get("APP_CHANNEL")

    # Output logs on stderr, with color support on consoles
    fmt = "{record.time} [{record.level_name:<8}] {record.channel}: {record.message}"
    handler = logbook.more.ColorizedStderrHandler(level=level, format_string=fmt)
    handler.push_application()

    # Log to papertrail
    if channel and PAPERTRAIL_HOST and PAPERTRAIL_PORT:
        setup_papertrail(project_name, channel, PAPERTRAIL_HOST, PAPERTRAIL_PORT)

    # Log to senty
    if channel and SENTRY_DSN:
        setup_sentry(project_name, channel, SENTRY_DSN)

    def logbook_factory(*args, **kwargs):
        # Logger given to structlog
        logbook.compat.redirect_logging()
        return logbook.Logger(level=level, *args, **kwargs)

    # Setup structlog over logbook, with args list at the end
    processors = [
        structlog.stdlib.PositionalArgumentsFormatter(),
        structlog.processors.StackInfoRenderer(),
        structlog.processors.format_exc_info,
        UnstructuredRenderer(),
    ]

    structlog.configure(
        context_class=structlog.threadlocal.wrap_dict(dict),
        processors=processors,
        logger_factory=logbook_factory,
        wrapper_class=structlog.stdlib.BoundLogger,
        cache_logger_on_first_use=True,
    )