Skip to content

Commit 29ad7d6

Browse files
committed
Juster feillogging.
1 parent 326a0c1 commit 29ad7d6

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/main/kotlin/no/nav/tms/statistikk/statistikkApi.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ fun Application.statistikkApi(
2323

2424
install(StatusPages) {
2525
val log = KotlinLogging.logger {}
26+
val securelog = KotlinLogging.logger("secureLog")
27+
2628
exception<Throwable> { call, cause ->
2729
when (cause) {
2830
is IllegalArgumentException -> {
29-
log.info { "Bad request til statistikkApi: $cause, ${cause.message.toString()}" }
31+
log.warn { "Bad request til statistikkApi" }
32+
securelog.warn(cause) { "Bad request til statistikkApi" }
3033
call.respond(HttpStatusCode.BadRequest, cause.message ?: "")
3134
}
3235
else -> {
33-
log.error { "Feil i statistikkApi: $cause, ${cause.message.toString()}" }
36+
log.error { "Feil i statistikkApi" }
37+
securelog.error(cause) { "Feil i statistikkApi" }
3438
call.respond(HttpStatusCode.InternalServerError)
3539
}
3640
}

src/main/resources/logback.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<configuration debug="true">
22
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"/>
3+
34
<property name="loggingPattern"
45
value="%d [%-5level] [%thread] %logger{5} %replace(- [%X{consumerId}, %X{callId}, %X{userId}] ){'- \[, , \] ',''}- %m%n"/>
6+
57
<appender name="stdout_json" class="ch.qos.logback.core.ConsoleAppender">
68
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
79
</appender>
10+
811
<appender name="secureLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
912
<file>/secure-logs/secure.log</file>
1013
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
@@ -15,10 +18,13 @@
1518
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
1619
<maxFileSize>50MB</maxFileSize>
1720
</triggeringPolicy>
18-
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
21+
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
1922
</appender>
23+
2024
<root level="INFO">
2125
<appender-ref ref="stdout_json"/>
22-
<appender-ref ref="secureLog"/>
2326
</root>
24-
</configuration>
27+
<logger name="secureLog" level="INFO" additivity="false">
28+
<appender-ref ref="secureLog"/>
29+
</logger>
30+
</configuration>

0 commit comments

Comments
 (0)