Created
January 22, 2016 16:01
-
-
Save Zagrebelin/77a8aeeed22338eeba50 to your computer and use it in GitHub Desktop.
setup_logging
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
def setup_logging(project='test'): | |
def namer(name): | |
return name.replace('.txt.', '.')+".txt" | |
logging.getLogger("requests").setLevel(logging.WARNING) | |
logger = logging.getLogger('') | |
formatter = logging.Formatter('%(asctime)s %(message)s', datefmt='%Y.%m.%d %H:%M:%S') | |
logger.setLevel(logging.DEBUG) | |
console = logging.StreamHandler() | |
console.setLevel(logging.INFO) | |
console.setFormatter(formatter) | |
logger.addHandler(console) | |
if os.environ.get('%s_DEBUG' % project, '').lower() in ('true', 'yes', 'on', '1'): | |
debug_file = logging.handlers.TimedRotatingFileHandler('logging.debug.txt', when='midnight') | |
info_file.namer = namer | |
debug_file.setLevel(logging.DEBUG) | |
debug_file.setFormatter(formatter) | |
logger.addHandler(debug_file) | |
if os.environ.get('%s_DEVELOP' % project, '').lower() not in ('true', 'yes', 'on', '1'): | |
exception_file = logging.handlers.SMTPHandler(......) | |
exception_file.setLevel(logging.ERROR) | |
logger.addHandler(exception_file) | |
info_file = logging.handlers.TimedRotatingFileHandler('logging.info.txt', when='midnight') | |
info_file.namer = namer | |
info_file.setLevel(logging.INFO) | |
info_file.setFormatter(formatter) | |
logger.addHandler(info_file) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment