If a particular module is logging using log4perl then is there any way to get the name of that module using log4perl internally. or message is logged from srcipt(.pl) can we get the name of script also using log4perl only apart from using caller or any function which doesnt use log4perl function explicitly.
Asked
Active
Viewed 75 times
1 Answers
2
For classes or packages, you can do that. It's documented with Log::Log4perl::Layout::PatternLayout. In your log pattern, use one of the following.
%C Fully qualified package (or class) name of the caller
And for the name of a script:
%F File where the logging event occurred
These ones are also useful:
%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
The documentation of Log::Log4perl::Layout::PatternLayout itself has even more details.
Here's an example of how to use this with a config file.
log4perl.appender.LOGFILE.layout=PatternLayout log4perl.appender.LOGFILE.layout.ConversionPattern=[%r] %F %L %c - %m%n

simbabque
- 53,749
- 8
- 73
- 136
-
1@Mr_perl I don't know. Please include the things you already know in your question next time. It took me a few minutes to find this in the documentation, and I would not have needed to do that had you included your own research. – simbabque Apr 18 '17 at 09:45
-
@Mr_perl: Then I don't understand your requirement. It sounds like you want to get the name of the calling module from within that module, but it already knows its own name. Please give a proper example of the code you want to write. – Borodin Apr 18 '17 at 11:09
-
1@Mr_perl please include more information into your question. You can [edit your question](http://stackoverflow.com/posts/43467923/edit). – simbabque Apr 18 '17 at 11:37