separate info, error logs using logback grails code example
Example: separate info, error logs using logback grails
import grails.util.BuildSettings
import grails.util.Environment
import org.springframework.boot.ApplicationPid
import java.nio.charset.Charset
statusListener(OnConsoleStatusListener)
if (!System.getProperty("PID")) {
System.setProperty("PID", (new ApplicationPid()).toString())
}
conversionRule 'clr', org.springframework.boot.logging.logback.ColorConverter
conversionRule 'wex', org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter
appender('STDOUT', ConsoleAppender) {
encoder(PatternLayoutEncoder) {
charset = Charset.forName('UTF-8')
pattern =
'%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} ' +
'%clr(%5p) ' +
'%clr(%property{PID}){magenta} ' +
'%clr(---){faint} %clr([%15.15t]){faint} ' +
'%clr(%-40.40logger{39}){cyan} %clr(:){faint} ' +
'%m%n%wex'
}
}
root(WARN, ['STDOUT'])
if(Environment.current == Environment.DEVELOPMENT) {
root(INFO, ['STDOUT'])
def targetDir = BuildSettings.TARGET_DIR
if(targetDir) {
appender("FULL_STACKTRACE", FileAppender) {
file = "${targetDir}/stacktrace.log"
append = true
encoder(PatternLayoutEncoder) {
pattern = "%level %logger - %msg%n"
}
}
logger("StackTrace", ERROR, ['FULL_STACKTRACE'], false )
}
}