Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j show package name

Right now for my ConversionPattern I have:

log4j.appender.A1.layout.ConversionPattern=%d{yyyy MMM dd HH:mm:ss,SSS} %5p [%t] (%F:%L) - %m%n

What I'd like to do is also include the full package name with the class (%F:%L) but I can't find any config to do so in the docs. I do understand that this will be slower, but it's only for debugging and not when the system will be in production.

like image 873
Stephane Grenier Avatar asked Apr 07 '10 18:04

Stephane Grenier


People also ask

How do I check my log4j package?

The installed version 1 of Log4j can be found using the apt list command again. The instruction is written in the below attached image. There comes another bash script that can be used to find out all the installed versions of Log4j and its vulnerability as well.

Which package contains log4j?

log4j. The main log4j package. Implement this interface for your own strategies for outputting log statements.

What is the file name for log4j?

By default, Log4j looks for a configuration file named log4j2. xml (not log4j. xml) in the classpath. You can also specify the full path of the configuration file with this system property: -Dlog4j.configurationFile=path/to/log4j2.xml.

Where can I find log4j properties?

Sample log4j Configuration Files During Content Engine installation, two log4j sample files are placed on the system in the ContentEngine\config\samples\ folder: log4j. properties.


2 Answers

Maybe I just misunderstand you, but %C will output your class with package.

From your referenced docs:

%C

Used to output the fully qualified class name of the caller issuing the logging request. This conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets.

If a precision specifier is given, then only the corresponding number of right most components of the class name will be printed. By default the class name is output in fully qualified form.

For example, for the class name "org.apache.xyz.SomeClass", the pattern %C{1} will output "SomeClass".

WARNING Generating the caller class information is slow. Thus, use should be avoided unless execution speed is not an issue.

Update: In many cases you can use %c also, which will print out the full class with package also, if your category is your class-name. For example when your doing stuff like this when initializing your Log:

private static final Log LOG = LogFactory.getLog(MyClazz.class);

Using %c is not slow.

like image 142
Michael Konietzka Avatar answered Oct 19 '22 07:10

Michael Konietzka


Using C{1} is slow. Please see the details below:

As per the following link:

Used to output the fully qualified class name of the caller issuing the logging request. This conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets. If a precision specifier is given, then only the corresponding number of right most components of the class name will be printed. By default the class name is output in fully qualified form.

For example, for the class name org.apache.xyz.SomeClass, the pattern %C{1} will output SomeClass.

WARNING Generating the caller class information is slow. Thus, use should be avoided unless execution speed is not an issue.

like image 2
Rakesh Dondlapally Avatar answered Oct 19 '22 09:10

Rakesh Dondlapally