Skip to content

Instantly share code, notes, and snippets.

@atulkumar2
Created December 4, 2020 15:28
Show Gist options
  • Save atulkumar2/886cd1f7feb8926a9c66491907aceeec to your computer and use it in GitHub Desktop.
Save atulkumar2/886cd1f7feb8926a9c66491907aceeec to your computer and use it in GitHub Desktop.
import logging
IS_LOGGING_INITIALIZED = False
class LogFile:
filename = 'mylogging.log'
maxBytes = (1000*5000)
backupCount = 10
format = '%(asctime)s %(message)s'
datefmt = '%m/%d/%Y %I:%M:%S %p'
def createlogging():
global IS_LOGGING_INITIALIZED
if IS_LOGGING_INITIALIZED:
return
formatter = logging.Formatter(LogFile.format)
rotatingHandler = handlers.RotatingFileHandler(
LogFile.filename, maxBytes=LogFile.maxBytes, backupCount=LogFile.backupCount)
rotatingHandler.setLevel(logging.INFO)
rotatingHandler.setFormatter(formatter)
streamHandler = logging.StreamHandler(sys.stdout)
streamHandler.setFormatter(formatter)
logging.basicConfig(
level=logging.INFO,
format=LogFile.format, datefmt=LogFile.datefmt,
handlers=[
rotatingHandler,
streamHandler
])
IS_LOGGING_INITIALIZED = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment