0
如果一个特定的模块使用log4perl然后记录该消息记录的名字有什么办法让使用log4perl内部该模块的名称。或从srcipt(.pl)记录消息,除了使用调用者或任何不明确使用log4perl函数的函数之外,我们是否也可以使用log4perl来获取脚本的名称。越来越模块或脚本中使用log4perl
如果一个特定的模块使用log4perl然后记录该消息记录的名字有什么办法让使用log4perl内部该模块的名称。或从srcipt(.pl)记录消息,除了使用调用者或任何不明确使用log4perl函数的函数之外,我们是否也可以使用log4perl来获取脚本的名称。越来越模块或脚本中使用log4perl
对于类或包,你可以这样做。这是documented with Log::Log4perl::Layout::PatternLayout。在您的日志模式中,使用以下任一项。
%C Fully qualified package (or class) name of the caller
而对于一个脚本的名称:
%F File where the logging event occurred
这些的人也很有用:
%l Fully qualified name of the calling method followed by the callers source the file name and line number between parentheses. %L Line number within the file where the log statement was issued
Log::Log4perl::Layout::PatternLayout本身的文档有更多的细节。
的如何使用配置文件使用此Here's an example。
log4perl.appender.LOGFILE.layout=PatternLayout log4perl.appender.LOGFILE.layout.ConversionPattern=[%r] %F %L %c - %m%n
@Mr_perl我不知道。请在下次您的问题中包含您已经知道的内容。我花了几分钟的时间在文档中找到它,如果你包括自己的研究,我不需要这么做。 – simbabque
@Mr_perl:那我不明白你的要求。这听起来像你想从该模块中获取调用模块的名称,但它已经知道它自己的名称。请给出一个你想写的代码的正确例子。 – Borodin
@Mr_perl请在您的问题中提供更多信息。你可以[编辑你的问题](http://stackoverflow.com/posts/43467923/edit)。 – simbabque