Skip to content

Instantly share code, notes, and snippets.

@UBarney
Last active July 8, 2017 12:46
Show Gist options
  • Save UBarney/6bfdcc35eb25a9985cb765da368e102b to your computer and use it in GitHub Desktop.
Save UBarney/6bfdcc35eb25a9985cb765da368e102b to your computer and use it in GitHub Desktop.
log to diffierent file
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')
@UBarney
Copy link
Author

UBarney commented Jul 8, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment