Loki4j Logback

Loki4j Logback

  • Docs
  • Contributing
  • Help
  • GitHub

›Logback

Logback

  • Configuration
  • Labels and structured metadata
  • JSON Message Layout
  • Protobuf Support
  • Apache HttpClient
  • Grafana Cloud
  • Monitoring
  • Tracing
  • Migration Guide
  • Compatibility Matrix
  • Old Docs

Switching to Protobuf format

By default, Loki4j uses JsonEncoder that converts log batches into JSON format specified by Loki API. This encoder does not use any extra libs for JSON generation.

If you want to use ProtobufEncoder, you need to add the following dependency to your project:

Maven
Gradle
<dependency>
<groupId>com.github.loki4j</groupId>
<artifactId>loki-protobuf</artifactId>
<version>0.0.2_pb4.29.0</version>
</dependency>
implementation 'com.github.loki4j:loki-protobuf:0.0.2_pb4.29.0'

This library contains pre-generated encoders for Loki Protobuf format along with the proper version of Protobuf runtime and Snappy as transitive dependencies.

Then you can explicitly specify ProtobufEncoder by setting class attribute for format section:

<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
    <format class="com.github.loki4j.logback.ProtobufEncoder">
        ...
    </format>
</appender>

Selecting a version of Protobuf

If your project already depends on a certain version of Protobuf, you will have to use a proper version of loki-protobuf as well.

You can change the Protobuf version bundled with loki-protobuf by modifying the _pbX.Y.0 part. The list of supported Protobuf versions is available in PB-VERSION file.

If the version you need is not listed in there, consider the following options:

  • Add the version you need to PB-VERSION file and create a PR to Loki4j. Once merged, this will add one more publishing configuration to loki-protobuf, and the new Protobuf version will be available to everyone

  • Put Loki-specific .proto files inside your project and generate corresponding Java files yourself. This option is considered advanced, so you should be able to figure out all the details you might need from the loki-protobuf's source code

← JSON Message LayoutApache HttpClient →
Loki4j Logback
Docs
Reference
Community
GitHubLinkedIn
More
Powered by Docusaurus
Copyright © 2020-2025 Anton Nekhaev and Contributors