Java
Collect logs from your Java projects using Logback.
Add the Logtail Logback adapter to your pom.xml
1
<dependency>
2
<groupId>com.logtail</groupId>
3
<artifactId>logback-logtail</artifactId>
4
<version>0.1.0</version>
5
</dependency>
Copied!
Add Logback and JAX-RS implementation to your dependencies, for example:
nlog.config
1
<dependency>
2
<groupId>ch.qos.logback</groupId>
3
<artifactId>logback-classic</artifactId>
4
<version>1.2.6</version>
5
</dependency>
6
​
7
<dependency>
8
<groupId>ch.qos.logback</groupId>
9
<artifactId>logback-core</artifactId>
10
<version>1.2.6</version>
11
</dependency>
12
​
13
<dependency>
14
<groupId>com.fasterxml.jackson.jaxrs</groupId>
15
<artifactId>jackson-jaxrs-json-provider</artifactId>
16
<version>2.12.4</version>
17
</dependency>
18
​
19
<dependency>
20
<groupId>javax.ws.rs</groupId>
21
<artifactId>javax.ws.rs-api</artifactId>
22
<version>2.1.1</version>
23
</dependency>
24
​
25
<dependency>
26
<groupId>org.glassfish.jersey.core</groupId>
27
<artifactId>jersey-client</artifactId>
28
<version>2.33</version>
29
</dependency>
30
​
31
<dependency>
32
<groupId>org.glassfish.jersey.inject</groupId>
33
<artifactId>jersey-hk2</artifactId>
34
<version>2.33</version>
35
</dependency>
Copied!
Add Logtail appenders to your logback.xml file. Here's a sample logback.xml you can modify with your own LOGTAIL_INGEST_KEY
1
<?xml version="1.0" encoding="UTF-8"?>
2
<configuration>
3
​
4
<appender name="LogtailHttp" class="com.logtail.logback.LogtailAppender">
5
<appName>MyApp</appName>
6
<ingestKey>${LOGTAIL_INGEST_KEY}</ingestKey>
7
<mdcFields>requestId,requestTime</mdcFields>
8
<mdcTypes>string,int</mdcTypes>
9
</appender>
10
​
11
<appender name="Logtail" class="ch.qos.logback.classic.AsyncAppender">
12
<appender-ref ref="LogtailHttp" />
13
<queueSize>500</queueSize>
14
<discardingThreshold>0</discardingThreshold>
15
<includeCallerData>true</includeCallerData>
16
</appender>
17
​
18
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
19
<encoder>
20
<pattern>%d{HH:mm} %-5level %msg%n</pattern>
21
</encoder>
22
</appender>
23
​
24
<root level="INFO">
25
<appender-ref ref="Logtail" />
26
<appender-ref ref="Console" />
27
</root>
28
​
29
</configuration>
Copied!

Additional configuration

If you want, you can specify a custom pattern, but it shouldn't be necessary:
1
<configuration>
2
<appender name="LogtailHttp" class="com.logtail.logback.LogtailAppender">
3
<encoder>
4
<pattern>[%thread] %msg%n</pattern>
5
</encoder>
6
7
<!-- ... -->
8
</appender>
9
10
<!-- ... -->
11
</configuration>
Copied!
We also support the Mapped Diagnostic Context, which you can configure with the mdFields and mdcTypes configuration attributes.

Structured logging with Logback

We automatically recognize JSON passed at the end of any String messages, and make it available for query and further analysis.
For example, if you log the following message ...
logger.info("My message { \"id\": 1, \"value\": \"text\" }");
... we automatically index both id and value into separate parameters you can then query.
Last modified 27d ago