Log4j - Invalid element or attribute in RollingRandomAccessFile

I am new to Log4J (and Java in general). I am trying to print some logs in logstash. I ran into some problems with inline logstash code like log4j. For this reason, I wanted to use the json_event layout approach . Although I believe that everything is correctly configured, I get an error message when I start the application, which reads:

ERROR: RollingRandomAccessFile contains an invalid element or attribute "layout".

I do not understand why I get this, or how to resolve it. I'm more interested in getting my json_event logs than anything else. Currently my log4j2.xml file is as follows:

<Configuration status="WARN" monitorInterval="30">
  <Appenders>
    <RollingRandomAccessFile name="RollingFile" fileName="/logs/recent.log"
      filePattern="/logs/$${date:yyyy-MM}/server-%d{yyyy-MM-dd-HH}-%i.log.gz">
      <layout class="net.logstash.log4j.JSONEventLayoutV1" />
      <Policies>
        <TimeBasedTriggeringPolicy interval="4" modulate="true"/>
        <SizeBasedTriggeringPolicy size="100 MB"/>
      </Policies>
    </RollingRandomAccessFile>
    <Async name="AsyncFile">
      <AppenderRef ref="RollingFile"/>
    </Async>
  </Appenders>
  <Loggers>
    <Logger name="com.myApp" level="trace" additivity="false">
      <AppenderRef ref="AsyncFile"/>
    </Logger>
    <Root level="trace">
      <AppenderRef ref="AsyncFile"/>
    </Root>
  </Loggers>
</Configuration>

To run my application, I run the following at a command prompt:

java -Dlog4j.configurationFile=log4j2.xml -cp "/home/ubuntu/jsonevent-layout-1.6.jar" -Xms256m -Xmx1024m -jar myApp.jar

jsonevent-layout-1.6.jar. , . , , log4j . , . json_event. - ? , .

+4
2

.

;

<layout class="net.logstash.log4j.JSONEventLayoutV1" />

:

<RollingRandomAccessFile name="RollingFile" fileName="/logs/recent.log"
  filePattern="/logs/$${date:yyyy-MM}/server-%d{yyyy-MM-dd-HH}-%i.log.gz">
  <net.logstash.log4j.JSONEventLayoutV1>
     ..properties here
  </net.logstash.log4j.JSONEventLayoutV1>
  <Policies>
    <TimeBasedTriggeringPolicy interval="4" modulate="true"/>
    <SizeBasedTriggeringPolicy size="100 MB"/>
  </Policies>
</RollingRandomAccessFile>
0

net.logstash.log4j.JSONEventLayoutV1 github.com/logstash/log4j-jsonevent-layout Log4J2. github.com/maartenbosteels/log4j-jsonevent-layout, Log4J2. , . . , , log4j2.xml .

<RollingRandomAccessFile name="RollingFile" fileName="/logs/recent.log"
   filePattern="/logs/$${date:yyyy-MM}/server-%d{yyyy-MM-dd-HH}-%i.log.gz">
   <JSONEventLayoutV1>
   <Policies>
     <TimeBasedTriggeringPolicy interval="4" modulate="true"/>
     <SizeBasedTriggeringPolicy size="100 MB"/>
   </Policies>
</RollingRandomAccessFile>
0

Source: https://habr.com/ru/post/1535841/


All Articles