|
1 | | - |
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 |
54 | 2 |
|
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 | +[](https://betterstack.com/logs) |
118 | 6 |
|
119 | | -### Configuration options |
| 7 | +[](LICENSE.md) |
| 8 | + |
120 | 9 |
|
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) |
122 | 11 |
|
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 |
136 | 13 |
|
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/) |
140 | 15 |
|
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! |
142 | 18 |
|
143 | | -We automatically parse a JSON object at the end of any string log message. |
| 19 | +--- |
144 | 20 |
|
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) |
0 commit comments