[
https://issues.apache.org/jira/browse/LOG4J2-3416?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17506095#comment-17506095
]
Volkan Yazici commented on LOG4J2-3416:
---------------------------------------
[~sagarsalal], your configuration works for me without a problem.
I have adopted your {{log4j2.xml}} as follows:
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Routing name="RollingFile">
<Routes pattern="$${ctx:env}">
<Route key="mock">
<RollingFile name="RollingFilePerf" fileName="xyz.log"
filePattern="/tmp/LOG4J2-3416/mock-xyz.log.%d{yyyy-MM-dd-HH-mm}.gz">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS}
[%t] %-5p %c{1.}.%M():%L %X - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="60"
modulate="true"/>
</Policies>
</RollingFile>
</Route>
<!-- This route is chosen if ThreadContext has no value for key
ROUTINGKEY. -->
<Route key="$${ctx:ROUTINGKEY}">
<RollingFile name="Rolling-default" fileName="xyz.log"
filePattern="/tmp/LOG4J2-3416/unknown-xyz.log.%d{yyyy-MM-dd-HH-mm}.gz">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS}
[%t] %-5p %c{1.}.%M():%L %X - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="60"
modulate="true"/>
</Policies>
</RollingFile>
</Route>
<Route key="$${ctx:env}">
<RollingFile name="RollingFileProd" fileName="xyz.log"
filePattern="/tmp/LOG4J2-3416/prod-xyz.log.%d{yyyy-MM-dd-HH-mm}.gz">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss,SSS}
[%t] %-5p %c{1.}.%M():%L %X - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="60"
modulate="true"/>
</Policies>
</RollingFile>
</Route>
</Routes>
</Routing>
</Appenders>
<Loggers>
<Logger name="com.xyz" additivity="false" includeLocation="true">
<appender-ref ref="RollingFile" level="INFO"/>
</Logger>
<Root level="INFO">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
{code}
I have created a simple Java class:
{code:java}
package com.xyz;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
public class Log4j2_3416 {
private static final Logger LOGGER = LogManager.getLogger();
public static void main(String[] args) {
ThreadContext.put("env", "mock");
LOGGER.trace("this should not get logged");
LOGGER.info("this should be logged");
}
}
{code}
Ran the code against Log4j 2.17.2 and got the following output:
{code}
$ zcat /tmp/LOG4J2-3416/mock-xyz.log.2022-03-14-09-59.gz
2022-03-14 09:51:16,630 [main] INFO c.x.Log4j2_3416.main():12 {env=mock} -
this should be logged
{code}
See the line number and the method name above.
> Line Number Not getting printed in log file
> -------------------------------------------
>
> Key: LOG4J2-3416
> URL: https://issues.apache.org/jira/browse/LOG4J2-3416
> Project: Log4j 2
> Issue Type: Bug
> Components: Appenders
> Affects Versions: 2.17.0
> Reporter: Sagar Salal
> Priority: Major
> Attachments: log4j2.xml
>
>
> I am not able to print line numbers in logs. I am using 2.17.0 version and
> using pattern
> <PatternLayout
> pattern="%d\{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %logger\{36}:%L %X - %m%n" />.
>
> I have tried with multiple patterns but issue still persists. It is basically
> neglecting *%L.* Can anyone please have a look at this?
--
This message was sent by Atlassian Jira
(v8.20.1#820001)