Last active
December 1, 2020 13:38
-
-
Save RajeshKrSahoo/00f0e43d7cef5f141a07c3e2d2577150 to your computer and use it in GitHub Desktop.
logger code
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
| class createLog: | |
| def formatLog(filename): | |
| import os, logging | |
| logfilename = os.path.join(os.path.expanduser('~'), 'xyz', '{0}.log'.format(filename)) | |
| print('Log file path : Home/xyz/{}'.format(logfilename)) | |
| # create logger | |
| logger = logging.getLogger(__name__) | |
| logger.setLevel(logging.DEBUG) | |
| # create console handler and set level to debug | |
| ch = logging.StreamHandler() | |
| ch.setLevel(logging.DEBUG) | |
| # create file handler and set level to debug | |
| fh = logging.FileHandler(logfilename) | |
| fh.setLevel(logging.DEBUG) | |
| # create formatter | |
| formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') | |
| # add formatter to ch | |
| ch.setFormatter(formatter) | |
| # add formatter to ch | |
| fh.setFormatter(formatter) | |
| # add ch to logger | |
| #logger.addHandler(ch) | |
| logger.addHandler(fh) | |
| return logger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment