Skip to content

Commit

Permalink
Add loki4j logback appenders for local, prod, and stdout (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Villavicencio authored Jun 25, 2024
1 parent a7d8a74 commit 9a79591
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 39 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ ext {
set('resilienceReactorVersion', '1.6.1')
set('resilienceRateLimiterVersion', '1.6.1')
set('lokiLogbackAppenderVersion', '1.5.1')
set('micrometerCoreVersion', '1.12.2')
}

jar {
Expand All @@ -71,7 +72,7 @@ dependencies {
implementation "software.pando.crypto:salty-coffee:${pandoCryptoVersion}"
implementation "org.apache.commons:commons-collections4:${apacheCollectionsVersion}"
implementation "com.github.loki4j:loki-logback-appender:${lokiLogbackAppenderVersion}"
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation "io.micrometer:micrometer-core:${micrometerCoreVersion}"
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
annotationProcessor "org.mapstruct:mapstruct-processor:${mapStructVersion}"
Expand Down
6 changes: 1 addition & 5 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@ spring:

application:
callback:
url: https://rivenbot.app

logging:
level:
root: DEBUG
url: https://rivenbot.app
85 changes: 52 additions & 33 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -1,44 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Local configuration -->
<SpringProfile name="local">
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<url>http://localhost:3100/loki/api/v1/push</url>
</http>
<format>
<label>
<pattern>level=%level</pattern>
<readMarkers>true</readMarkers>
</label>
<message>
<pattern>%-5level [%.5(${HOSTNAME})] %.10thread %logger{20} | %msg %ex</pattern>
</message>
</format>
</appender>
<appender name="LOKI_LOCAL" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<url>http://localhost:3100/loki/api/v1/push</url>
<connectionTimeoutMs>60000</connectionTimeoutMs>
<requestTimeoutMs>10000</requestTimeoutMs>
</http>
<format>
<label>
<pattern>level=%level</pattern>
<readMarkers>true</readMarkers>
</label>
<message>
<pattern>%-5level [%.5(${HOSTNAME})] %.10thread %logger{20} | %msg %ex</pattern>
</message>
</format>
</appender>
<root level="INFO">
<appender-ref ref="LOKI"/>
</root>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<!-- Production configuration -->
<appender name="LOKI_PROD" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<url>http://loki:3100/loki/api/v1/push</url>
<connectionTimeoutMs>60000</connectionTimeoutMs>
<requestTimeoutMs>10000</requestTimeoutMs>
</http>
<format>
<label>
<pattern>level=%level</pattern>
<readMarkers>true</readMarkers>
</label>
<message>
<pattern>%-5level [%.5(${HOSTNAME})] %.10thread %logger{20} | %msg %ex</pattern>
</message>
</format>
<verbose>true</verbose>
<metricsEnabled>true</metricsEnabled>
</appender>

<SpringProfile name="prod">
<root level="INFO">
<appender-ref ref="LOKI"/>
<appender-ref ref="LOKI_PROD"/>
<appender-ref ref="STDOUT"/>
</root>
</SpringProfile>

<!-- Production configuration -->
<SpringProfile name="prod">
<appender name="LOKI" class="com.github.loki4j.logback.Loki4jAppender">
<http>
<url>http://rivenbot.app:3100/loki/api/v1/push</url>
</http>
<format>
<label>
<pattern>level=%level</pattern>
<readMarkers>true</readMarkers>
</label>
<message>
<pattern>%-5level [%.5(${HOSTNAME})] %.10thread %logger{20} | %msg %ex</pattern>
</message>
</format>
</appender>
<SpringProfile name="local">
<root level="INFO">
<appender-ref ref="LOKI"/>
<appender-ref ref="LOKI_LOCAL"/>
<appender-ref ref="STDOUT"/>
</root>
</SpringProfile>
</configuration>

0 comments on commit 9a79591

Please sign in to comment.