Open nehaev opened 3 years ago
@nehaev I am interested in using a stand-alone Loki client to send logs directly to Loki without any appender. It looks like you have all the items here checked off except for tests. By chance is this ready to be used and if yes, could you share a code snippet. Thanks!
Hi @SanjulaGanepola, currently it's possible only if you're willing to dive deep into the code, and potentially deal with some incompatible changes in Loki4j's internal interfaces in future.
The high-level code snippet looks like this:
var pipelineConf = PipelineConfig.builder()
...
.build();
var pipeline = new AsyncBufferPipeline(pipelineConf);
pipeline.start();
// Send messages in async fashion
pipeline.append(timeStampMs, nanos, stream, message);
...
// When done, stop the pipeline
pipeline.stop();
But there are a lot of low-level nuances, of course. Anyway, you can always find a working version that uses exactly these interfaces in https://github.com/loki4j/loki-logback-appender/blob/main/loki-logback-appender/src/main/java/com/github/loki4j/logback/Loki4jAppender.java
Separate a Loki client from logback specifics in order to provide a library that can be used independently of logging frameworks (e.g. logback, log4j).