Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val ctx = LoggerContext.getContext(false)
- val root = ctx.rootLogger
- val cfg = ctx.configuration
- val layout = PatternLayout.newBuilder()
- .withPattern("[%d{HH:mm:ss}] [%25.25t] [%level]: %msg%n")
- .withCharset(StandardCharsets.UTF_8)
- .withAlwaysWriteExceptions(true)
- .withConfiguration(cfg)
- .build()
- val policy = OnStartupTriggeringPolicy.createPolicy(0)
- val strategy = DefaultRolloverStrategy.newBuilder()
- .withMax("10")
- .withMin("1")
- .withFileIndex("min")
- .withConfig(cfg)
- .build()
- val fileAppender = (
- RollingFileAppender.newBuilder<RollingFileAppenderBuilder>() as RollingFileAppender.Builder<RollingFileAppenderBuilder>
- ).apply {
- name = "File"
- configuration = cfg
- setLayout(layout)
- withFileName(File("latest.log").absolutePath.toString())
- withFilePattern(File("latestn.log").absolutePath.toString() + ".%i")
- withAppend(true)
- withImmediateFlush(true)
- withPolicy(policy)
- withStrategy(strategy)
- }.build()
- fileAppender.start()
- cfg.addAppender(fileAppender)
- root.addAppender(fileAppender)
- root.info("test")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement