Created
December 4, 2020 15:28
-
-
Save atulkumar2/886cd1f7feb8926a9c66491907aceeec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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