About
Tjahzi is a Java client for Grafana Loki.
Latest releases:
Design principles
Logging should be lightweight and not interfere with main business tasks of threads that happen to log a message. Asking the logging subsystem to log a message should be as CPU efficient as possible. That's a truism. Apart from computation itself there are many other causes of jitter (varying speed of code execution). Thread can be slowed down by excessive allocations, by initialization code running in constructors of unnecessarily allocated objects, by garbage collector activity that is triggered by it. There can by configuration refresh checks on logging path, inter thread signaling etc.
To avoid these effects we strive to adhere to the following principles (and document any violations):
- Lock free and wait free API
- Allocation free in steady state
You can compare this with design principles of Aeron which are close to our hearts.
Architecture
+-------------+ Log
| Application |----------------+
| Thread 1 | |
+-------------+ |
|
. \|/
+----+---------------+ +---------+
. Log | | | I/O |
--------------->+ Log buffer +-->--->--+ thread |
. | | | (Netty) |
+----------+---------+ +---------+
. /|\
|
+-------------+ Log |
| Application |----------------------+
| Thread N |
+-------------+
Log4j Appender
On top of a Core component with rather simplistic API we intend to build several layers that make it truly useful. Log4j2
appender seemed like a good first.
Example Log4j2 configuration
This example sets up a root logger with a Loki appender.
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF" shutdownHook="disable" packages="pl.tkowalcz.tjahzi.log4j2">
<Loggers>
<Root level="INFO">
<AppenderRef ref="Loki"/>
</Root>
</Loggers>
<appenders>
<Loki name="Loki">
<host>${sys:loki.host}</host>
<port>${sys:loki.port}</port>
<ThresholdFilter level="ALL"/>
<PatternLayout>
<Pattern>%X{tid} [%t] %d{MM-dd HH:mm:ss.SSS} %5p %c{1} - %m%n%exception{full}</Pattern>
</PatternLayout>
<Header name="server" value="127.0.0.1"/>
<Label name="server" value="127.0.0.1"/>
</Loki>
</appenders>
</configuration>
LICENSE
This work is released under MIT license. Feel free to use, copy and modify this work as long as you credit original authors. Pull and feature requests as welcome.