Skip to content

Commit

Permalink
feat: How to stream runtime logs as JSON ouptut to a remote server (#…
Browse files Browse the repository at this point in the history
…2952)

Add a section on logging page to explain how to configure log4j to
stream the log as JSON output to a remote server

---------

Co-authored-by: Vincent HEMERY <vincent.hemery@bonitasoft.com>
  • Loading branch information
benjaminParisel and vhemery authored Jan 8, 2025
1 parent ae5e090 commit c12d480
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions modules/setup-dev-environment/pages/logging.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,63 @@ Here is an example of the Log4j2 configuration for the logger used in the exampl
<Logger name="org.bonitasoft.groovy.script" level="TRACE"/>
----


==== Use JSON format for logs

The default configuration contains an unused `Console-JSON` appender which formats logs as JSON.

[source, xml]
----
<Appenders>
<!-- use json logger if json output is required -->
<Console name="Console-JSON" target="SYSTEM_OUT">
<JSONLayout compact="true" eventEol="true" properties="true" stacktraceAsString="true">
<KeyValuePair key="timestamp" value="$${date:yyyy-MM-dd'T'HH:mm:ss.SSSZ}"/>
</JSONLayout>
</Console>
<!-- [...] -->
</Appenders>
----

To use it, you can update the `AppenderRef` in the `Loggers` block or add a new one.

[source, xml]
----
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console-JSON"/>
</Root>
</Loggers>
----

==== Stream logs to a remote server

You need to declare a Socket appender in `log4j-appenders.xml` to stream to a remote server. You can choose to use Socket with various formats, such as JSONLayout or PatternLayout.

As example, this configuration is used to stream JSON-formatted log entries to a remote server, such as Logstash, for further processing and analysis.

[source, xml]
----
<Socket name="runtimeLogSocket" host="<host>" port="<port>">
<JSONLayout compact="true" eventEol="true" properties="true" stacktraceAsString="true">
<KeyValuePair key="timestamp" value="$${date:yyyy-MM-dd'T'HH:mm:ss.SSSZ}"/>
</JSONLayout>
</Socket>
----

Then, do not forget to reference this new appender in `Loggers` block:

[source, xml]
----
<Loggers>
<Root level="INFO">
<!-- [...] -->
<AppenderRef ref="runtimeLogSocket"/> <!-- Add this AppenderRef -->
<!-- [...] -->
</Root>
</Loggers>
----

=== Bonita Studio

To change the Bonita Studio log level (usually to debug Studio), go to the Studio installation folder, configuration directory, and edit the `config.ini` file. You need to set the property `eclipse.log.level` to one of the following values: INFO, WARNING or ERROR.
Expand Down

0 comments on commit c12d480

Please sign in to comment.