来自Django 文档 https://docs.djangoproject.com/en/1.7/topics/logging/#examples,这是日志记录的示例格式:
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s: %(message)s'
}
}
这会打印如下内容:
错误 2012-05-22 14:33:07,261 浏览量 42892 4398727168 你好
是否有可以包含在字符串格式中的项目列表?例如,我希望能够查看正在创建消息的函数和应用程序,例如:
错误时间 myproject.myapp.views.login_function 消息
From Python 日志模块文档 http://docs.python.org/library/logging.html#logrecord-attributes:
asctime: %(asctime)s
人类可读的时间LogRecord https://docs.python.org/2/library/logging.html#logging.LogRecord被创建。默认情况下,其格式为“2003-07-08 16:49:45,896”(逗号后面的数字是时间的毫秒部分)。
created: %(created)f
时间当LogRecord https://docs.python.org/2/library/logging.html#logging.LogRecord已创建(由返回time.time() https://docs.python.org/2/library/time.html#time.time).
filename: %(filename)s
文件名部分pathname.
funcName: %(funcName)s
包含日志记录调用的函数名称。
关卡名称: %(levelname)s
消息的文本日志记录级别(“DEBUG”、“INFO”、“WARNING”、“ERROR”、“CRITICAL”)。
levelno: %(levelno)s
消息的数字日志记录级别(DEBUG、INFO、WARNING、ERROR、CRITICAL)。
lineno: %(lineno)d
发出日志记录调用的源行号(如果可用)。
module: %(module)s
模块(名称部分filename).
msecs: %(msecs)d
毫秒部分的时间LogRecord https://docs.python.org/2/library/logging.html#logging.LogRecord被创建。
message: %(message)s
记录的消息,计算为msg % args
。这是在以下情况下设置的Formatter.format() https://docs.python.org/2/library/logging.html#logging.Formatter.format被调用。
name: %(name)s
用于记录呼叫的记录器的名称。
pathname: %(pathname)s
发出日志记录调用的源文件的完整路径名(如果可用)。
process: %(process)d
进程 ID(如果可用)。
进程名: %(processName)s
进程名称(如果可用)。
相对创建: %(relativeCreated)d
时间(以毫秒为单位)LogRecord https://docs.python.org/2/library/logging.html#logging.LogRecord创建时间,相对于日志记录模块加载的时间。
thread: %(thread)d
线程 ID(如果可用)。
线程名: %(threadName)s
线程名称(如果可用)。
以下论点也可用于Formatter.format() https://docs.python.org/2/library/logging.html#logging.Formatter.format,尽管它们不打算包含在格式字符串中:
args:
参数元组合并为msg产生消息。
exc_info:
异常元组(à lasys.exc_info https://docs.python.org/2/library/sys.html#sys.exc_info)或者,如果没有发生异常,None
.
msg:
原始日志记录调用中传递的格式字符串。合并于args生成消息或任意对象(请参阅使用任意对象作为消息 https://docs.python.org/2/howto/logging.html#arbitrary-object-messages).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)