python打印什么意思_python打印日志,extra是什么意思

展开全部

extra是用户自定义的dict. 这些key/value在格式化的时候可以直接引用。

extra可以用来传递额外的日志信息,尤其是上下32313133353236313431303231363533e78988e69d8331333339656531文信息。

例如:FORMAT = '%(asctime)-15s %(clientip)s %(user)-8s %(message)s'

logging.basicConfig(format=FORMAT)

d = { 'clientip' : '192.168.0.1', 'user' : 'fbloggs' }

logger = logging.getLogger('tcpserver')

logger.warning('Protocol problem: %s', 'connection reset', extra=d)

这里除了protocol错误描述外,还附加了客户IP和用户名信息。

如果配置了一些非文本格式的handler,结构化的数据会更容易存储和查询。

例如,Sentry的logging handler允许用户用extra.data来传递任意信息,并自动记录到web界面。logger.error('There was some crazy error', exc_info=True, extra={

'culprit': 'my.view.name',

'fingerprint': [...],

'data': {

# You may specify any values here and Sentry will log and output them

'username': request.user.username,

}

})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值