I\'m using SLF4J with Logback in a JAX-RS application... I want to log to JSON in such a way that my message is not encoded again but printed raw into the logfile:
At t
here is an updated (2016) groovy logback config that dumps out your logs in json format to a file, and debug lines in the console. Took me all day to figure out so i thought i'd update the thread.
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.core.ConsoleAppender
import ch.qos.logback.core.rolling.FixedWindowRollingPolicy
import ch.qos.logback.core.rolling.RollingFileAppender
import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy
import net.logstash.logback.encoder.LogstashEncoder
import static ch.qos.logback.classic.Level.INFO
import static ch.qos.logback.classic.Level.WARN
def PROJECT_ID = "com.foo"
appender("file", RollingFileAppender) {
file = "/tmp/logs/${PROJECT_ID}.json"
encoder(LogstashEncoder)
rollingPolicy(FixedWindowRollingPolicy) {
maxIndex = 1
fileNamePattern = "logs/${PROJECT_ID}.json.%i"
}
triggeringPolicy(SizeBasedTriggeringPolicy) {
maxFileSize = "1MB"
}
}
appender("STDOUT", ConsoleAppender) {
encoder(PatternLayoutEncoder) {
pattern = "%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n"
}
}
logger("com.foo", INFO, ["STDOUT", "file"], false)
root(WARN, ["STDOUT", "file"])