10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

logbackの設定をgroovyでやってみた。(logback.groovy)

Posted at

はじめに

脱XML

最低限やってみた

import static ch.qos.logback.classic.Level.*

import java.nio.charset.Charset

import ch.qos.logback.core.ConsoleAppender
import ch.qos.logback.core.rolling.RollingFileAppender
import ch.qos.logback.core.rolling.TimeBasedRollingPolicy
import ch.qos.logback.core.status.OnConsoleStatusListener
import ch.qos.logback.classic.encoder.PatternLayoutEncoder

statusListener(OnConsoleStatusListener)
scan("10 minutes")

def defaultCharset = Charset.forName("UTF-8")
def defaultPattern = "%date [%highlight(%-5level)] [%thread] [%cyan(%logger{32})] - %message%n"
def defaultHistory = 365
def defaultFilename = "/var/log/hoge/hoge.log"

appender("CONSOLE", ConsoleAppender) {

  encoder(PatternLayoutEncoder) {
    charset = defaultCharset
    pattern = defaultPattern
  }

}

appender("FILE", RollingFileAppender) {

  fileName = defaultFilename

  encoder(PatternLayoutEncoder) {
    charset = defaultCharset
    pattern = defaultPattern
  }

  rollingPolicy(TimeBasedRollingPolicy) {
    maxHistory = defaultHistory
    fileNamePattern = "${defaultFilename}.%d{yyyy-MM-dd}.gz"
  }

}

root INFO, ["CONSOLE", "FILE"]

参考サイト

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?