Grafana Loki Logging

Log data can be automatically routed to Grafana Loki. Grafana Loki is a horizontally scalable, highly available, multi-tenant log aggregation system inspired by Prometheus. It is designed to be very cost effective and easy to operate. It does not index the contents of the logs, but rather a set of labels for each log stream.

Support is enabled by including the following module in the overlay:

1
2
3
4
5
<dependency>
    <groupId>org.apereo.cas</groupId>
    <artifactId>cas-server-support-logging-config-loki</artifactId>
    <version>${cas.version}</version>
</dependency>
1
implementation "org.apereo.cas:cas-server-support-logging-config-loki:${project.'cas.version'}"
1
2
3
4
5
6
7
8
9
dependencyManagement {
    imports {
        mavenBom "org.apereo.cas:cas-server-support-bom:${project.'cas.version'}"
    }
}

dependencies {
    implementation "org.apereo.cas:cas-server-support-logging-config-loki"
}
1
2
3
4
5
6
7
8
9
10
dependencies {
    /*
        The following platform references should be included automatically and are listed here for reference only.

        implementation enforcedPlatform("org.apereo.cas:cas-server-support-bom:${project.'cas.version'}")
        implementation platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
        
    */
    implementation "org.apereo.cas:cas-server-support-logging-config-loki"
}

With the above module, you may then declare a specific appender to communicate with Loki:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<Appenders>
    <Loki name="LokiAppender">
        <host>loki.mydomain.com</host>
        <port>3100</port>
        <useSSL>false</useSSL>
        <username>...</username>
        <password>...</password>
    
        <PatternLayout>
            <Pattern>%X{tid} [%t] %d{MM-dd HH:mm:ss.SSS} %5p %c{1} - %m%n%exception{full}</Pattern>
        </PatternLayout>
        <ThresholdFilter level="ALL"/>
        <Header name="X-Scope-OrgID" value="Apereo"/>
        <Label name="server" value="cas"/>
        <LogLevelLabel>log_level</LogLevelLabel>
    </Loki>
</Appenders>
...
<Loggers>
    <Root level="error">
        <AppenderRef ref="LokiAppender"/>
    </Root>
</Loggers>

The plugin by default sends POST requests to /loki/api/v1/push HTTP endpoint. The above configuration will configure the appender to call to URL: http://loki.mydomain.com:3100/loki/api/v1/push.