Skip to content

Instantly share code, notes, and snippets.

@sblask
Last active August 31, 2019 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sblask/7544685 to your computer and use it in GitHub Desktop.
Save sblask/7544685 to your computer and use it in GitHub Desktop.
Python logging configuration
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)5s - %(name)s - %(message)s',
filename=os.path.join(os.path.sep, 'path'),
)
def get_log_handler():
log_format = '%(asctime)s - %(levelname)5s - %(name)s - %(message)s'
log_filename = os.path.join(os.path.sep, 'path')
log_formatter = logging.Formatter(log_format)
log_handler = logging.handlers.RotatingFileHandler(
log_filename,
maxBytes=1024*1024,
backupCount=5,
)
log_handler.setFormatter(log_formatter)
return log_handler
logger = logging.getLogger(__name__)
logger.addHandler(get_log_handler())
logger.setLevel(logging.INFO)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment