All Downloads are FREE. Search and download functionalities are using the official Maven repository.

.work-tracker.examples.spring-boot-example.1.0.0-rc13.source-code.logback.groovy Maven / Gradle / Ivy

There is a newer version: 1.0.0-rc14
Show newest version
/**
 * Copyright 2019 Deere & Company
 *
 * This software may be modified and distributed under the terms
 * of the MIT license.  See the LICENSE file for details.
 */

import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import com.deere.isg.worktracker.MdcThreadNameJsonProvider
import com.deere.isg.worktracker.RootCauseTurboFilter
import com.deere.isg.worktracker.Work
import net.logstash.logback.composite.GlobalCustomFieldsJsonProvider
import net.logstash.logback.composite.loggingevent.*
import net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder

// This logback is for demonstration only

appender("STDOUT", ConsoleAppender) {
    encoder(PatternLayoutEncoder) {
        pattern = "%d{yyyy-MM-dd HH:mm:ss.SSS} %magenta([%thread]) %highlight(%-5level) %logger{36}.%M - user_id=%X{user_id} role=%X{role} - %msg%n"
    }
}

def APP_NAME = "spring-boot-example"
appender("FILEOUTPUT", RollingFileAppender) {
    file = "logs/application.log"
    encoder(LoggingEventCompositeJsonEncoder) {
        providers(LoggingEventJsonProviders) {
            globalCustomFields(GlobalCustomFieldsJsonProvider) {
                customFields = "{\"app\": \"${APP_NAME}\"}"
            }
            message(MessageJsonProvider)
            mdc(MdcJsonProvider) {
                excludeMdcKeyName = Work.THREAD_NAME
            }
            arguments(ArgumentsJsonProvider)
            threadName(MdcThreadNameJsonProvider)
            logLevelValue(LogLevelValueJsonProvider)
            logLevel(LogLevelJsonProvider)
            stackTrace(StackTraceJsonProvider)
            stackHash(StackHashJsonProvider)
            timestamp(LoggingEventFormattedTimestampJsonProvider)
            callerData(CallerDataJsonProvider)
        }
    }
    rollingPolicy(TimeBasedRollingPolicy) {
        fileNamePattern = "logs/application.log.%d{yyyy-MM-dd}"
        maxHistory = 2
        cleanHistoryOnStart = true
    }
}

turboFilter(RootCauseTurboFilter)

root(INFO, ["STDOUT", "FILEOUTPUT"])




© 2015 - 2024 Weber Informatics LLC | Privacy Policy