Skip to content

Instantly share code, notes, and snippets.

@suganoo
Last active October 17, 2017 09:27
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 suganoo/49888a18d1c250d2813ae3331489f067 to your computer and use it in GitHub Desktop.
Save suganoo/49888a18d1c250d2813ae3331489f067 to your computer and use it in GitHub Desktop.
ユーザー定義のLogRecord属性
# もちろん必要部分は書いてください
# 説明上formatだけ記述します。
......................
[formatter_hogehogeFormatter]
format=%(asctime)s%(tab)s%(hostname)s%(tab)s%(user)s%(tab)s%(message)s
import logging
import logging.config
logging.config.fileConfig("logging_formatter.conf")
hogelogger = logging.getLogger("hogehoge")
# このdictionaryが必要!
extra_args = {}
extra_args['tab'] = "\t"
extra_args['hostname'] = "hogehogeserver"
extra_args['user'] = "fugafugauser"
# ここが大事!!!
hogelogger.info(output, extra=extra_args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment