log4j2 in Java project - Can't find output

318 Views Asked by At

Im new here, Please help me to understand my new project's log4j2 configuration.

My question is:

  • How to get all Log outputs?

  • From where should I search log files?

Also how to save tomcat console outputs in the txt file?

I really appreciate your help and support, Today I want to learn something new from you guys! Thanks!

This is the log4j2.xml:

    <?xml version="1.0" encoding="UTF-8"?>

<configuration status="error" monitorInterval="1800">
    <Properties>
        <Property name="LOG_HOME">\Workspaces\logs\paymentweb</Property>
        <Property name="LOG_DEBUG">${LOG_HOME}\app\debug.log</Property>
        <Property name="LOG_INFO">${LOG_HOME}\app\info.log</Property>
        <Property name="LOG_ERROR">${LOG_HOME}\app\error.log</Property>
    </Properties>


    <appenders>

        <Console name="Console" target="SYSTEM_OUT">
        (onMismatch)-->
            <ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY"/>

            <PatternLayout pattern="%d{yyyy.MM.dd HH:mm:ss z} %-5level %class{36}.%M()/%L - %msg%xEx%n"/>
        </Console>


        <RollingRandomAccessFile name="app_debug" fileName="${LOG_DEBUG}" append="false" filePattern="${LOG_HOME}\$${date:yyyy-MM}\debug-%d{MM-dd-yyyy}-%i.log.gz">
            <Filters>
                <ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
            </Filters>
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5level %class{36}.%M()/%L - %msg%xEx%n"/>
            <Policies>
                <OnStartupTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="50 MB" />
                <TimeBasedTriggeringPolicy />
            </Policies>
        </RollingRandomAccessFile>


        <CustomRollingRandomAccessFile name="app_info" fileName="${LOG_INFO}" append="false" filePattern="${LOG_HOME}\$${date:yyyy-MM}\info-%d{MM-dd-yyyy}-%i.log.gz">
            <Filters>
                <ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
                <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5level %class{36}.%M()/%L - %msg%xEx%n"/>
            <Policies>
                <OnStartupTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="50 MB" />
                <TimeBasedTriggeringPolicy />
            </Policies>
        </CustomRollingRandomAccessFile>


        <CustomRollingRandomAccessFile name="app_error" fileName="${LOG_ERROR}" append="false" filePattern="${LOG_HOME}\$${date:yyyy-MM}\error-%d{MM-dd-yyyy}-%i.log.gz">
            <Filters>
                <ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
            <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5level %class{36}.%M()/%L - %msg%xEx%n"/>
            <Policies>
                <OnStartupTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="50 MB" />
                <TimeBasedTriggeringPolicy />
            </Policies>
        </CustomRollingRandomAccessFile>
    </appenders>


    <loggers>

        <root level="trace" additivity="false">
            <appender-ref ref="Console"/>  
            <appender-ref ref="app_debug"/>  
            <appender-ref ref="app_info"/>  
            <appender-ref ref="app_error"/>
       </root>
    </loggers>
 </configuration>
2

There are 2 best solutions below

1
Irwan Hendra On

all your logs are in \Workspaces\logs\paymentweb\app*.log

0
Remko Popma On

You can find out details about how your appenders are configured by enabling internal Log4j2 "status" logging.

At the top of your configuration file, change it to TRACE <configuration status="trace" monitorInterval="1800">. I believe this will show the full path of the file appenders on the console. (No guarantees for the custom appender CustomRollingRandomAccessFile.)

Also, you have a non-XML compliant snippet inside the <Console> appender configuration. This looks bad and should be removed:

(onMismatch)-->