Log4perl 过滤器可以访问映射的诊断上下文吗?
我正在编写一些 Perl CGI 脚本,并使用 Log4perl 来记录到各种文件。我认为能够将特定(或各种)用户的活动跟踪到单独的日志文件可能很有用。我可以在会话例程中放置一个钩子,将用户 ID 填充到 MDC 中,但我不知道有什么方法可以从 过滤器。据我所知,MDC仅用于模式创建。
这可以用 Log4perl 实现吗?
根据下面的建议,我在配置文件中添加了一个过滤器,但它仍然不起作用:
log4perl.appender.User = Log::Log4perl::Appender::File
log4perl.appender.User.filename = /data/wwwwii/logs/appUser.log
log4perl.appender.User.syswrite = 1
log4perl.appender.User.Filter = User
log4perl.appender.User.layout = PatternLayout
log4perl.appender.User.layout.ConversionPattern=%p{1} %d{ISO8601}Z [%03r] %15X{remoteAddr}/%05P %M %L --> %m%n
log4perl.filter.User = sub { Log::Log4perl::MDC->get('userId') == 12; }
我在进行会话查找后立即填充用户 ID,但我从未创建过 appUser.log 文件。我看不到任何错误。
I'm writting some Perl CGI scripts, and am using Log4perl to log to various files. I thought it may be useful to be able to trace a particular (or various) user's activities to a separate log file. I can put a hook into my session routine to stuff the userid into the MDC, but I don't know of any way to access the MDC from a filter. As far as I know, the MDC is only used for pattern creation.
Is this doable with Log4perl?
Per suggestion below I added a filter in my config file, but it's still not working:
log4perl.appender.User = Log::Log4perl::Appender::File
log4perl.appender.User.filename = /data/wwwwii/logs/appUser.log
log4perl.appender.User.syswrite = 1
log4perl.appender.User.Filter = User
log4perl.appender.User.layout = PatternLayout
log4perl.appender.User.layout.ConversionPattern=%p{1} %d{ISO8601}Z [%03r] %15X{remoteAddr}/%05P %M %L --> %m%n
log4perl.filter.User = sub { Log::Log4perl::MDC->get('userId') == 12; }
I stuff the userid as soon as I do the session lookup, but I never do get an appUser.log file created. No errors show up that I can see.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能这样做吗:
Can't you just do: