Last active
July 8, 2017 12:46
-
-
Save UBarney/6bfdcc35eb25a9985cb765da368e102b to your computer and use it in GitHub Desktop.
log to diffierent file
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
import logging | |
class LogHandler(object): | |
format = '%(levelname)s %(message)s' | |
files = { | |
'ERROR': 'error.log', | |
'CRITICAL': 'error.log', | |
'WARN': 'warn.log', | |
} | |
def write(self, msg): | |
type_ = msg[:msg.index(' ')] | |
with open(self.files.get(type_, 'log.log'), 'r+') as f: | |
f.write(msg) | |
logging.basicConfig(format=LogHandler.format, stream=LogHandler()) | |
logging.critical('foo') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from https://stackoverflow.com/questions/15147713/python-log-to-multiple-log-files