Pregunta

I've been working really hard to load log4j logs into LogStash (as seen here). Unfortunately, I learned that there is a bug associated with the approach I was trying to use. This has made me consider alternative approaches. This lead me to the log4j-jsonevent-layout.

I'm not very familiar with Java. I've downloaded the code from Git hub. I can successfully make the project in IntelliJ. However, I'm now stuck. I see two .class files. However, I do not see a .jar file or anything like that. From my understanding, I can't just copy and paste .class files. So, I'm not sure how to deploy this utility.

Beyond that, I believe I just need to update my log4j2.xml file to something like this:

<Configuration status="WARN" monitorInterval="30">
    <Appenders>
      <RollingRandomAccessFile name="RollingFile" fileName="/logs/current.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.myCompany" level="trace" additivity="false">
            <AppenderRef ref="AsyncFile"/>
        </Logger>
        <Root level="trace">
            <AppenderRef ref="AsyncFile"/>
        </Root>
    </Loggers>
</Configuration>

I feel like I'm close. If I can just figure out a) what I need to deploy and b) where to deploy it to. I think it'll work. Any help is significantly appreciated. A big proactive 'Thank you' to anyone in the Java community that can help.

¿Fue útil?

Solución

If you're using Maven to build your project, just add the project as a dependency.

http://search.maven.org/#search%7Cga%7C1%7Cnet.logstash.log4j

Otherwise download the jars manually from the central repository, and add them to your classpath.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top