Skip to content

Instantly share code, notes, and snippets.

@podhmo
Last active September 21, 2016 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save podhmo/056213a4cd51c2e611b963b36ae9cdbb to your computer and use it in GitHub Desktop.
Save podhmo/056213a4cd51c2e611b963b36ae9cdbb to your computer and use it in GitHub Desktop.
import logging
import wrap
logger = logging.getLogger(__name__)
wlogger = wrap.LoggerWrapper(logger)
def hello():
logger.info("hello")
def hello2():
wlogger.info("hello")
def log_with_additional_info(message, *args, **kwargs):
logger.info("additional: {}".format(message), *args, **kwargs)
def hello3():
log_with_additional_info("hello")
import logging
import hello
format = "time:%(asctime)s\tlevel:%(levelname)s\tmsg:%(message)s\tlocation:%(pathname)s(%(lineno)s)\tfn:%(funcName)s"
logging.basicConfig(level=logging.DEBUG, format=format)
hello.hello()
hello.hello2()
hello.hello3()
class LoggerWrapper:
def __init__(self, logger):
self.logger = logger
def info(self, *args, **kwargs):
# do something
self.logger.info(*args, **kwargs)
@podhmo
Copy link
Author

podhmo commented Sep 21, 2016

time:2016-09-22 04:32:56,354    level:INFO  msg:hello   location:~/work/hello.py(10)    fn:hello
time:2016-09-22 04:32:56,354    level:INFO  msg:hello   location:~/work/wrap.py(7)  fn:info
time:2016-09-22 04:32:56,354    level:INFO  msg:additional: hello   location:~/work/hello.py(18)    fn:log_with_additional_info

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