Using LogMX with log4j2

Notes, tips, and other usefull things on how to use LogMX

Moderator: admin

Post Reply
alfstglo
Posts: 2
Joined: Sun Sep 22, 2019 4:39 pm

Using LogMX with log4j2

Post by alfstglo » Sun Sep 22, 2019 5:19 pm

I am using JBoss 7.2, log4j2, and trying to use LogMX but LogMX does not show any of the logging. The logging shows up in the log file fp-server.log from my RollingFileAppender, and I have a Socket Appender to use with LogMX. On the Socket Appender (have tested with a pattern and XmlLayout, but can't see any logs in LogMX.

My Log4j2, Note i tried using XMLLayout and SerializedLayout but neither show logs in LogMX

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG" >
  <Appenders>
        <RollingFile name="server" fileName="${sys:logPath}\fp-server.log" filePattern="${sys:logPath}\fp-server.log.%i" append="true" immediateFlush="true">
            <PatternLayout><pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{10} - %msg%n</pattern></PatternLayout>
            <XMLLayout />
            <Policies>
                <SizeBasedTriggeringPolicy size="10 MB" />
            </Policies>
            <DefaultRolloverStrategy max="20" fileIndex="min"/>
        </RollingFile>
        <Socket name="socketTest" host="localhost" protocol="tcp" port="4560"  immediateFlush="true">
            <XMLLayout />
        </Socket>
        <Console name="STDOUT" target="SYSTEM_OUT">
            <PatternLayout pattern="[%-5level] %d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
        </Console>
  </Appenders>  
    
  <Loggers>
    <Root level="DEBUG">
      <AppenderRef ref="STDOUT"/>
      <AppenderRef ref="server"/>
      <AppenderRef ref="socketTest"/>
    </Root>
  </Loggers>
</Configuration>
Log4XML Setup
1. Copied log4j-api-2.11.2.jar, log4j-1.2-api-2.11.2.jar, and log4j-core-2.11.2.jar to LogMX_v7.8.0_eval\lib

Created log parser using Wizard:
1. Selected Received on a local TCP/UPD port
2. Selected Log4j / Logback
3. Selected Log4j XML format
4. Clicked Finish
5. Enter port 4560 - matched my log4j2.xml file

Log4j2 Debugging:

83 DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.SocketAppender].
83 DEBUG SocketAppender$Builder(advertise="null", connectTimeoutMillis="null", host="localhost", immediateFail="null", port="4560", protocol="TCP", reconnectDelayMillis="null", SocketOptions=null, SslConfiguration=null, bufferedIo="null", bufferSize="null", immediateFlush="true", ignoreExceptions="null", XMLLayout(org.apache.logging.log4j.core.layout.XMLLayout@7d27517c), name="socketTest", Configuration(C:\Users\alfstglo\log4j2.xml), Filter=null, ={})
Creating socket localhost:4560
DEBUG Starting TcpSocketManager TCP:localhost:4560
DEBUG createAppenderRef(ref="socketTest", level="null", Filter=null)
DEBUG createLogger(additivity="true", level="DEBUG", name="bls.security.jbossAuthenticator.NMLoginModule", includeLocation="null", ={bls, socketTest}, ={}, Configuration(C:\Users\alfstglo\log4j2.xml), Filter=null)

Nothing at all is shown in LogMX. Status is always "(no new entry, for [time])'

Any ideas? Using notepad++ to sort out logs is getting old.

admin
Site Admin
Posts: 506
Joined: Sun Dec 17, 2006 10:30 pm

Re: Using LogMX with log4j2

Post by admin » Mon Sep 23, 2019 3:45 am

Hello,

Did you open the logs tab in LogMX before your JBoss application? For Socket Appenders, LogMX should be started first so that somebody opens the TCP port and listens to it, otherwise the logging may never happen. Also, I'm a bit confused why you tried to add the Log4j JARs in LogMX: if you are using a text representation for your logs (i.e. not binary content), you don't need these JARs.

I have not tested yet, but if you can, I would advise using PatternLayout instead of XMLLayout for this SocketAppender, as the XML format is really verbose (poor performances) and is not always consistent across different Log4j versions. For example, you could try to replace, in your "<Socket>", the "<XMLLayout />" with the "<PatternLayout>" you have for "<RollingFile>".

Please let me know if you cannot use PatternLayout, or if it still doesn't work with PatternLayout, I will try to reproduce this issue (then in this case, please let me know the exact Log4j version you are using).

Xavier

alfstglo
Posts: 2
Joined: Sun Sep 22, 2019 4:39 pm

Re: Using LogMX with log4j2

Post by alfstglo » Mon Sep 23, 2019 5:13 pm

Without dropping the Log4j Jars in the /lib folder on the screen where the port "4560" is entered there is an error : Missing third-party JAR(s) file(s) for Logback, Log4j v1, Log4j v2. Click on the red dot(s) in the table above for more information. There was red dots for TCP-Serialized, but there is no red indicator for TCP - pattern, Log4j2.

I changed Socket Element to what Pattern:

Code: Select all

<Socket name="socketTest" host="localhost" protocol="tcp" port="4560"  immediateFlush="true">
<PatternLayout><pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{10} - %msg%n</pattern></PatternLayout>
 </Socket>
 
In the dialog where I entered Port, I had to uncheck Serialized, and then now my logging shows up. Thank you!

Post Reply