Collect logs from your Java applications using Logback.
Add Better Stack Logback appender to your pom.xml or build.gradle file:
You'll also need Logback. Spring Boot and the Quarkus quarkus-logging-logback extension already include it and manage its version.
Don't have Logback in your project yet?
Add logback-classic to your pom.xml or build.gradle file. It brings logback-core and slf4j-api along:
Logback 1.5 needs Java 11 or newer. On Java 8, use Logback 1.3, for example 1.3.16.
Set up log appenders in your logback.xml configuration:
Import and use the logger:
You should see your logs in Better Stack β Live tail.
Find structured data under the message_json field.
Better Stack parses any JSON at the end of the log line.
Please let us know at hello@betterstack.com.
We're happy to help! π
<objectMapperModule> tag.
For example, see adding JavaTimeModule on Github.
Keep all Jackson artifacts on one version, for example by importing com.fasterxml.jackson:jackson-bom, or the appender fails to start with NoClassDefFoundError.maxFlushTime, which is 30 seconds by default.Fine-tune logging with more options inside the <appender name="Logtail"> tag in logback.xml. The appender ignores out-of-range values with a warning that Logback prints at startup.
Appender options
Your Better Stack source token.
The ingesting URL of your source. Use the ingesting host listed in your source settings.
Application name for Better Stack indexation.
MDC fields that will be sent as metadata, separated by a comma.
MDC fields types that will be sent as metadata, in the same order as mdcFields are set up, separated by a comma. Possible values are string, boolean, int, and long.
Maximum number of messages in the queue. Messages over the limit will be dropped.
Batch size for the number of messages to be sent via the API.
Maximum wait time for a batch to be sent via the API, in milliseconds.
Connection timeout of the underlying HTTP client, in milliseconds.
Read timeout of the underlying HTTP client, in milliseconds.
Maximum number of retries for sending logs to Better Stack. After that, the current batch of logs will be dropped.
Number of milliseconds to sleep before retrying to send logs to Better Stack.
Maximum time to send queued logs when the application stops, in milliseconds. 0 means no limit.
Registers an add-on data type module for Jackson to serialize logged data, for example com.fasterxml.jackson.datatype.jsr310.JavaTimeModule. Can be used multiple times.
Want to try a more detailed example with Maven or Gradle?
See our Java Logtail example projects on GitHub.
We use cookies to authenticate users, improve the product user experience, and for personalized ads. Learn more.