Skip to content

Instantly share code, notes, and snippets.

Created October 7, 2013 06:42
Show Gist options
  • Save anonymous/6863426 to your computer and use it in GitHub Desktop.
Save anonymous/6863426 to your computer and use it in GitHub Desktop.
#coding: utf-8
from logging.handlers import SMTPHandler as _SMTPHandler
class SMTPHandler(_SMTPHandler):
def __init__(self, *args, **kwargs):
super(SMTPHandler, self).__init__(*args, **kwargs)
self._timeout = 15
Logging:
formatters:
brief:
format: "%(levelname)s <PID %(process)d:%(processName)s> %(name)s %(message)s"
filters: []
handlers:
console:
class: logging.StreamHandler
formatter: brief
email:
class: handlers.SMTPHandler
mailhost: !!python/tuple [smtp.gmail.com, 587]
fromaddr: [email protected]
toaddrs: [[email protected]]
subject: 'hello, this is from logging'
credentials: !!python/tuple [[email protected], yourpwd]
secure: !!python/tuple [] # force to start tls
file:
class: logging.handlers.RotatingFileHandler
filename: 'app.log'
loggers:
app:
propagate: true
level: INFO
handlers: [console]
app.notice:
propagate: false
level: WARNING
handlers: [console, file]
disable_existing_loggers: true
incremental: false
version: 1
#coding: utf-8
from time import sleep
import yaml
import logging
basic_logger = logging.getLogger('app')
notice_logger = logging.getLogger('app.notice')
def cal():
a, b = 1, 1
while True:
yield a + b
a, b = b, a + b
def is_noticable(x):
return x > 1000 and x % 5 == 0
def main():
for x in cal():
basic_logger.info('now: %d' % x)
if is_noticable(x):
notice_logger.warn('look: %d' % x)
sleep(1)
if __name__ == '__main__':
import logging.config
config = yaml.load(open('logging.yaml', 'r'))
print config
logging.config.dictConfig(config['Logging'])
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment