Skip to main content

setup logger bb

Project description

BB LOGGER

Description

  1. Remove all logger handlers and reformat log record ( can be extended )

  2. Provide some other logging method than default (info, error..)

How

call setup_logging() one time at begin of program

1. Remove all logger handlers and reformat log record

sample code

import logging
from bb_logger import setup_logging

logging.error('before setup, using old handler format')
# setup log with default 
setup_logging()
logging.error('after setup, using new default format')
# setup logger with extend format
setup_logging(extend_format="%(asctime)s - %(message)s")
logging.error('after setup with custom format, using extended format')

output

ERROR:root:before setup, using old handler format
[ERROR] after setup, using new default format
[ERROR]	2021-01-10 18:18:46,202 - after setup with custom format, using extended format

logging format details can be here

(*) extend_format logic

  • BASE_FORMAT = '[%(levelname)s]'
  • DEFAULT_FORMAT = BASE_FORMAT + ' %(message)s'
  • if extend_format is specified, FORMAT will be : BASE_FORMAT + '\t'+ extend_format
  • else DEFAULT_FORMAT wil be used  

2. Provide some other logging method than default(info, error..)

NOW SUPPORTED CUSTOM LEVEL (will be filtered and notify to slack, telegram, etc):

  • NOTI

EXAMPLE

must be used with logger, default logging will raise Error

import logging
from bb_logger import setup_logging
setup_logging()
logger = logging.getLogger()
logger.noti('noti level')

output

[NOTI] noti level

NOTE

CloudWatch now accept following pattern:

  • [ERROR]
  • [CRITICAL]
  • [NOTI]

Example:

  • "[ERROR] error log" will be matched

  • "some thing before [ERROR] error log" will be matched

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bb_logger-0.1.3.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

bb_logger-0.1.3-py2.py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page