# Log4j2 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. ## Quick start guide 1. Grab the no-dependency version of the appender: ```xml pl.tkowalcz.tjahzi log4j2-appender-nodep 0.9.17 ``` If you already use a compatible version of Netty in your project then to reduce the size of your dependencies include regular appender distribution: ```xml pl.tkowalcz.tjahzi log4j2-appender 0.9.17 ``` 1. Add `packages="pl.tkowalcz.tjahzi.log4j2"` attribute to your existing log4j2 configuration file. 1. Include minimal appender configuration: ```xml ${sys:loki.host} ${sys:loki.port} %X{tid} [%t] %d{MM-dd HH:mm:ss.SSS} %5p %c{1} - %m%n%exception{full} ``` 1. Reference the appender from inside one of your logger definitions: ```xml ``` ### Note on Loki HTTP endpoint and host/port configuration Tjahzi by default sends `POST` requests to `/loki/api/v1/push` HTTP endpoint. Specifying e.g. `loki.mydomain.com3100` will configure the appender to call to URL: `http://loki.mydomain.com:3100/loki/api/v1/push`. ### Grafana Cloud configuration Tjahzi can send logs to Grafana Cloud. It needs two things to be configured: - Set port number to `443` which switches HTTP client into HTTPS mode. - Specify `username` and `password` for HTTP basic authentication that Grafana uses. Password is your "Grafana.com API Key" and can be generated in "Grafana datasource settings". The host in below example is just for illustrative purposes. ```xml logs-prod-us-central1.grafana.net 443 ... ... ... ``` ## Advanced configuration This example sets up a root logger with a Loki appender. Note that `pl.tkowalcz.tjahzi.log4j2` is added to `packages` attribute of configuration so that the appender can be found. ```xml ${sys:loki.host} ${sys:loki.port} %X{tid} [%t] %d{MM-dd HH:mm:ss.SSS} %5p %c{1} - %m%n%exception{full}