Skip to content

Commit 1391601

Browse files
authored
Merge pull request #10 from logtail/sl/rebrand_plus_fixes
Rebrand, rename config key, add deps, fixes
2 parents 324684b + bbb1d50 commit 1391601

File tree

17 files changed

+113
-187
lines changed

17 files changed

+113
-187
lines changed

.github/workflows/java_build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ jobs:
2929
- name: Build with Maven on Java 8
3030
run: mvn -B clean package --file pom.xml
3131
env:
32-
LOGTAIL_INGEST_KEY: ${{ secrets.LOGTAIL_INGEST_KEY }}
32+
BETTER_STACK_SOURCE_TOKEN: ${{ secrets.BETTER_STACK_SOURCE_TOKEN }}
3333
- name: Set up JDK
3434
uses: actions/setup-java@v1
3535
with:
3636
java-version: 11
3737
- name: Build with Maven on Java 8
3838
run: mvn -B clean package --file pom.xml
3939
env:
40-
LOGTAIL_INGEST_KEY: ${{ secrets.LOGTAIL_INGEST_KEY }}
40+
BETTER_STACK_SOURCE_TOKEN: ${{ secrets.BETTER_STACK_SOURCE_TOKEN }}

README.md

Lines changed: 13 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,21 @@
1-
![Java Build](https://github.com/logtail/logback-logtail/workflows/Java%20Build/badge.svg)
2-
3-
# Logtail Logback appender
4-
5-
This library provides an appender for [logback](https://logback.qos.ch), allowing to send your logs to the [Logtail](https://logtail.com) online logging platform, via our HTTPS Ingest API. MDC thread-bound data can be send, indexed and searched into your Logtail dashboard.
6-
7-
8-
## Introduction
9-
10-
This library provides an appender for [logback](https://logback.qos.ch), allowing you to send logs to our logging platform [Logtail](https://logtail.com) logging platform, via our HTTPS Ingest API. MDC thread-bound data can be send, indexed and searched into your Logtail dashboard.
11-
12-
This library relies on a JAX-RS v2 implementation (of your choice) with a Jackson JSON mapper.
13-
14-
### How to use it
15-
16-
First, copy this dependency into your `pom.xml` file.
17-
18-
```xml
19-
<dependency>
20-
<groupId>com.logtail</groupId>
21-
<artifactId>logback-logtail</artifactId>
22-
<version>{revnumber}</version>
23-
</dependency>
24-
```
25-
26-
Add Logback to your dependencies, and if you don't already have one in your project, add a JAX-RS implementation into your `pom.xml` like [Jersey](https://search.maven.org/artifact/org.glassfish.jersey.core/jersey-client), which is the one we use in the unit tests, [RESTEasy](https://search.maven.org/artifact/org.jboss.resteasy/resteasy-client) or [Apache CXF](https://search.maven.org/artifact/org.apache.cxf/cxf-rt-rs-client).
27-
28-
Example dependencies:
29-
30-
```xml
31-
<dependency>
32-
<groupId>ch.qos.logback</groupId>
33-
<artifactId>logback-classic</artifactId>
34-
<version>1.2.11</version>
35-
</dependency>
36-
37-
<dependency>
38-
<groupId>ch.qos.logback</groupId>
39-
<artifactId>logback-core</artifactId>
40-
<version>1.2.11</version>
41-
</dependency>
42-
43-
<dependency>
44-
<groupId>com.fasterxml.jackson.jaxrs</groupId>
45-
<artifactId>jackson-jaxrs-json-provider</artifactId>
46-
<version>2.13.3</version>
47-
</dependency>
48-
49-
<dependency>
50-
<groupId>jakarta.ws.rs</groupId>
51-
<artifactId>jakarta.ws.rs-api</artifactId>
52-
<version>3.0.0</version>
53-
</dependency>
1+
# [Better Stack](https://betterstack.com/logs) Logback appender
542

55-
<dependency>
56-
<groupId>jakarta.inject</groupId>
57-
<artifactId>jakarta.inject-api</artifactId>
58-
<version>2.0.1</version>
59-
</dependency>
60-
61-
<dependency>
62-
<groupId>jakarta.activation</groupId>
63-
<artifactId>jakarta.activation-api</artifactId>
64-
<version>2.1.0</version>
65-
</dependency>
66-
67-
<dependency>
68-
<groupId>org.glassfish.jersey.core</groupId>
69-
<artifactId>jersey-client</artifactId>
70-
<version>3.0.4</version>
71-
</dependency>
72-
73-
<dependency>
74-
<groupId>org.glassfish.jersey.inject</groupId>
75-
<artifactId>jersey-hk2</artifactId>
76-
<version>3.0.4</version>
77-
</dependency>
78-
```
79-
80-
Then, copy the following two Logtail appenders to your `classpath:/logback.xml` file. Here's a sample configuration:
81-
82-
```xml
83-
<?xml version="1.0" encoding="UTF-8"?>
84-
<configuration>
85-
86-
<appender name="LogtailHttp" class="com.logtail.logback.LogtailAppender">
87-
<appName>MyApp</appName>
88-
<ingestKey>${LOGTAIL_INGEST_KEY}</ingestKey>
89-
<mdcFields>requestId,requestTime</mdcFields>
90-
<mdcTypes>string,int</mdcTypes>
91-
</appender>
92-
93-
<appender name="Logtail" class="ch.qos.logback.classic.AsyncAppender">
94-
<appender-ref ref="LogtailHttp" />
95-
<queueSize>500</queueSize>
96-
<discardingThreshold>0</discardingThreshold>
97-
<includeCallerData>true</includeCallerData>
98-
</appender>
99-
100-
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
101-
<encoder>
102-
<pattern>%d{HH:mm} %-5level %msg%n</pattern>
103-
</encoder>
104-
</appender>
105-
106-
<root level="INFO">
107-
<appender-ref ref="Logtail" />
108-
<appender-ref ref="Console" />
109-
</root>
110-
111-
</configuration>
112-
```
113-
114-
Finally, you have to provide a `LOGTAIL_INGEST_KEY`, an API key you'll find in the Logtail console when creating a source. If you don't provide an API key, the appender will be automatically disabled (with a warning).
115-
116-
The `queueSize` and `discardingThreshold` are native Logback AsyncAppender attributes. Read the [official docs](https://logback.qos.ch/manual/appenders.html#AsyncAppender) to learn more.
117-
3+
📣 Logtail is now part of Better Stack · [Learn more ⇗](https://betterstack.com/press/introducing-better-stack/)
4+
5+
[![Better Stack](https://user-images.githubusercontent.com/19272921/154085622-59997d5a-3f91-4bc9-a815-3b8ead16d28d.jpeg)](https://betterstack.com/logs)
1186

119-
### Configuration options
7+
[![MIT License](https://img.shields.io/badge/license-MIT-blue)](LICENSE.md)
8+
![Java Build](https://github.com/logtail/logback-logtail/workflows/Java%20Build/badge.svg)
1209

121-
* You can use your own logging pattern, by using the `encoder` option, e.g.
10+
Experience SQL-compatible structured log management based on ClickHouse. [Learn more ⇗](https://betterstack.com/logs)
12211

123-
```xml
124-
<configuration>
125-
<appender name="LogtailHttp" class="com.logtail.logback.LogtailAppender">
126-
<encoder>
127-
<pattern>[%thread] %msg%n</pattern>
128-
</encoder>
129-
130-
<!-- ... -->
131-
</appender>
132-
133-
<!-- ... -->
134-
</configuration>
135-
```
12+
## Documentation
13613

137-
* Set up comma-separated MDC keys to index (from the MDC thread local binding).
138-
* Set up one type for each MDC key. Possible types are string, boolean, int and long. The last two result in an indexed number in your Logtail console. You can then use these values as metrics and create Grafana dashboards around those.
139-
* You can try to set up a specific `connectTimeout` and `readTimeout` for the underlying JAX-RS client.
14+
[Getting started ⇗](https://betterstack.com/docs/logs/java/)
14015

141-
### JSON parameters parsing
16+
## Need help?
17+
Please let us know at [hello@betterstack.com](mailto:hello@betterstack.com). We're happy to help!
14218

143-
We automatically parse a JSON object at the end of any string log message.
19+
---
14420

145-
For example, if you log the following message : `My message { "id": 1, "value": "text" }`, then Logtail will index both `id` and `value` into separate parameters you can then query.
21+
[MIT license](https://github.com/logtail/logback-logtail/blob/main/LICENSE.md), [example projects](https://github.com/logtail/logback-logtail/tree/main/examples)

examples/gradle/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# Example gradle Hello world application
2-
With integrated Logtail logging
1+
# Better Stack Gradle example
32

4-
* Edit [src/main/resources/logback.xml](src/main/resources/logback.xml)
5-
and replace `<!-- YOUR LOGTAIL TOKEN -->` with your source token from [logtail.com](http://logtail.com)
6-
* Run `gradle run` from this directory
7-
* You should see a "Hello world" log in your source
3+
* Get your source token at [Better Stack -> Sources](http://logs.betterstack.com/team/0/sources).
4+
* Edit [src/main/resources/logback.xml](src/main/resources/logback.xml) and replace `<!-- YOUR SOURCE TOKEN -->` with your source token.
5+
* Run `gradle run` from this directory.
6+
* You should see a `Hello world` log in [Better Stack -> Live tail](https://logs.betterstack.com/team/0/tail).
87

examples/gradle/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ dependencies {
1414
implementation 'jakarta.ws.rs:jakarta.ws.rs-api:3.0.0'
1515
implementation 'jakarta.inject:jakarta.inject-api:2.0.1'
1616
implementation 'jakarta.activation:jakarta.activation-api:2.1.0'
17+
implementation 'jakarta.annotation:jakarta.annotation-api:2.1.1'
1718
implementation 'org.glassfish.jersey.core:jersey-client:3.0.4'
19+
implementation 'org.glassfish.jersey.core:jersey-common:3.0.4'
1820
implementation 'org.glassfish.jersey.inject:jersey-hk2:3.0.4'
21+
implementation 'org.slf4j:slf4j-api:1.7.7'
1922
}
2023

2124
application {
2225
mainClass = 'com.logtail.example.App'
23-
}
26+
}

examples/gradle/src/main/resources/logback.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<configuration debug="true">
22
<appender name="LogtailHttp" class="com.logtail.logback.LogtailAppender">
3-
<appName>Example app</appName>
3+
<appName>Better Stack Gradle example app</appName>
44
<batchSize>1</batchSize>
5-
<ingestKey><!-- YOUR LOGTAIL TOKEN --></ingestKey>
5+
<sourceToken><!-- YOUR SOURCE TOKEN --></sourceToken>
66
<mdcFields>requestId,requestTime</mdcFields>
77
<mdcTypes>string,int</mdcTypes>
88
</appender>

examples/maven/README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
# Example maven Hello world application
2-
With integrated Logtail logging
1+
# Better Stack Maven example
32

4-
* Edit [src/main/resources/logback.xml](src/main/resources/logback.xml)
5-
and replace `<!-- YOUR LOGTAIL TOKEN -->` with your source token from [logtail.com](http://logtail.com)
6-
* Run
7-
8-
`mvn compile -e exec:java -Dexec.mainClass="com.logtail.example.App"`
9-
10-
from this directory
11-
* You should see a "Hello world" log in your source
3+
* Get your source token at [Better Stack -> Sources](http://logs.betterstack.com/team/0/sources).
4+
* Edit [src/main/resources/logback.xml](src/main/resources/logback.xml) and replace `<!-- YOUR SOURCE TOKEN -->` with your source token.
5+
* Run `mvn compile -e exec:java -Dexec.mainClass="com.logtail.example.App"` from this directory.
6+
* You should see a "Hello world" log in [Better Stack -> Live tail](https://logs.betterstack.com/team/0/tail).

examples/maven/pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<version>0.0.1-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

10-
<name>Logtail Example project</name>
10+
<name>Better Stack Example project</name>
1111
<url>https://github.com/logtail/logback-logtail/</url>
1212

1313
<properties>
@@ -58,11 +58,21 @@
5858
<artifactId>jakarta.activation-api</artifactId>
5959
<version>2.1.0</version>
6060
</dependency>
61+
<dependency>
62+
<groupId>jakarta.annotation</groupId>
63+
<artifactId>jakarta.annotation-api</artifactId>
64+
<version>2.1.1</version>
65+
</dependency>
6166
<dependency>
6267
<groupId>org.glassfish.jersey.core</groupId>
6368
<artifactId>jersey-client</artifactId>
6469
<version>3.0.4</version>
6570
</dependency>
71+
<dependency>
72+
<groupId>org.glassfish.jersey.core</groupId>
73+
<artifactId>jersey-common</artifactId>
74+
<version>3.0.4</version>
75+
</dependency>
6676
<dependency>
6777
<groupId>org.glassfish.jersey.inject</groupId>
6878
<artifactId>jersey-hk2</artifactId>

examples/maven/src/main/resources/logback.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<configuration debug="true">
22
<appender name="LogtailHttp" class="com.logtail.logback.LogtailAppender">
3-
<appName>Example app</appName>
4-
<ingestKey><!-- YOUR LOGTAIL TOKEN --></ingestKey>
3+
<appName>Better Stack Maven example app</appName>
4+
<sourceToken><!-- YOUR SOURCE TOKEN --></sourceToken>
55
<mdcFields>requestId,requestTime</mdcFields>
66
<mdcTypes>string,int</mdcTypes>
77
</appender>

src/main/java/com/logtail/logback/LogtailAppender.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
import java.util.stream.Collectors;
2525

2626
/**
27-
* Logback appender for sending logs to <a href="https://logtail.com">logtail.com</a>.
27+
* Logback appender for sending logs to <a href="https://logs.betterstack.com">betterstack.com</a>.
2828
*
2929
* @author tomas@logtail.com
3030
*/
3131
public class LogtailAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
3232

33-
private static final String CUSTOM_USER_AGENT = "Logtail Logback Appender";
33+
private static final String CUSTOM_USER_AGENT = "Better Stack Logback Appender";
3434

3535
private final Logger errorLog = LoggerFactory.getLogger(LogtailAppender.class);
3636

@@ -48,7 +48,7 @@ public class LogtailAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
4848

4949
protected String appName;
5050

51-
protected String ingestUrl = "https://in.logtail.com";
51+
protected String ingestUrl = "https://in.logs.betterstack.com";
5252

5353
protected List<String> mdcFields = new ArrayList<>();
5454

@@ -105,7 +105,7 @@ protected void append(ILoggingEvent event) {
105105

106106
// Length 8+ means "Bearer " plus token, as a simple test
107107
if (!this.headers.containsKey("Authorization") || this.headers.getFirst("Authorization").toString().trim().length() < 8) {
108-
errorLog.warn("Empty ingest API key for Logtail ; disabling LogtailAppender");
108+
errorLog.warn("Missing Source token for Better Stack - disabling LogtailAppender. Find out how to fix this at: https://betterstack.com/docs/logs/java ");
109109
this.disabled = true;
110110
return;
111111
}
@@ -130,15 +130,15 @@ protected void flush() {
130130

131131
if (response.getStatus() != 202) {
132132
LogtailResponse logtailResponse = convertResponseToObject(response);
133-
errorLog.error("Error calling Logtail : {} ({})", logtailResponse.getError(), response.getStatus());
133+
errorLog.error("Error calling Better Stack : {} ({})", logtailResponse.getError(), response.getStatus());
134134
}
135135

136136
batch.clear();
137137
} catch (JsonProcessingException e) {
138138
errorLog.error("Error processing JSON data : {}", e.getMessage());
139139

140140
} catch (Exception e) {
141-
errorLog.error("Error trying to call Logtail : {}", e.getMessage());
141+
errorLog.error("Error trying to call Better Stack : {}", e.getMessage());
142142
}
143143
}
144144

@@ -154,7 +154,7 @@ protected LogtailResponse convertResponseToObject(Response response) throws Json
154154
}
155155

156156
/**
157-
* Call Logtail API posting given JSON formated string.
157+
* Call Better Stack API posting given JSON formated string.
158158
*
159159
* @param jsonData
160160
* a json oriented map
@@ -238,12 +238,26 @@ public void setEncoder(PatternLayoutEncoder encoder) {
238238
}
239239

240240
/**
241-
* Sets your Logtail ingest API key.
241+
* Sets your Better Stack source token.
242+
*
243+
* @param sourceToken
244+
* your Better Stack source token
245+
*/
246+
public void setSourceToken(String sourceToken) {
247+
this.headers.add("Authorization", String.format("Bearer %s", sourceToken));
248+
}
249+
250+
/**
251+
* Deprecated! Kept for backward compatibility.
252+
* Sets your Better Stack source token if unset.
242253
*
243254
* @param ingestKey
244-
* your ingest key
255+
* your Better Stack source token
245256
*/
246257
public void setIngestKey(String ingestKey) {
258+
if (this.headers.containsKey("Authorization")) {
259+
return;
260+
}
247261
this.headers.add("Authorization", String.format("Bearer %s", ingestKey));
248262
}
249263

@@ -258,27 +272,27 @@ public void setAppName(String appName) {
258272
}
259273

260274
/**
261-
* Sets the Logtail ingest API url.
275+
* Sets the Better Stack ingest API url.
262276
*
263277
* @param ingestUrl
264-
* Logtail url
278+
* Better Stack ingest url
265279
*/
266280
public void setIngestUrl(String ingestUrl) {
267281
this.ingestUrl = ingestUrl;
268282
}
269283

270284
/**
271-
* Sets the MDC fields that needs to be sent inside Logtail metadata, separated by a comma.
285+
* Sets the MDC fields that will be sent as metadata, separated by a comma.
272286
*
273287
* @param mdcFields
274-
* MDC fields to use
288+
* MDC fields to include in structured logs
275289
*/
276290
public void setMdcFields(String mdcFields) {
277291
this.mdcFields = Arrays.asList(mdcFields.split(","));
278292
}
279293

280294
/**
281-
* Sets the MDC fields types that will be sent inside Logtail metadata, in the same order as <i>mdcFields</i> are set
295+
* Sets the MDC fields types that will be sent as metadata, in the same order as <i>mdcFields</i> are set
282296
* up, separated by a comma. Possible values are <i>string</i>, <i>boolean</i>, <i>int</i> and <i>long</i>.
283297
*
284298
* @param mdcTypes

0 commit comments

Comments
 (0)