Last active
October 2, 2022 02:01
-
-
Save mjtiempo/6c02ffdaa8bb87c4e91f6e51e2ff7b17 to your computer and use it in GitHub Desktop.
Logging to stdout and file in python
This file contains hidden or 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
''' | |
src: https://stackoverflow.com/a/46098711/2433866 | |
''' | |
import sys | |
import logging | |
import logging.handlers | |
logging.basicConfig( | |
level=logging.INFO, | |
format="[%(asctime)s] %(levelname)s in %(module)s: %(message)s", | |
handlers=[ | |
logging.handlers.RotatingFileHandler( | |
'main.log', | |
maxBytes=(1048576*5), | |
backupCount=9 | |
), | |
logging.StreamHandler(sys.stdout) | |
] | |
) | |
''' test below ''' | |
mainLogger = logging.getLogger('mainLogger') | |
newLogger = logging.getLogger('newLogger') | |
for i in range(100000): | |
mainLogger.info(f"mainLogger {i}"); | |
newLogger.info(f"newLogger! {i}"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment