-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoggingUtils.kt
34 lines (28 loc) · 1.04 KB
/
LoggingUtils.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* Copyright 2016-present The KotlinNLP Authors. All Rights Reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/.
* ------------------------------------------------------------------*/
package com.kotlinnlp.nlpserver
import org.apache.log4j.*
import org.apache.log4j.spi.RootLogger
/**
* Setup the logging.
* This function should be called after the creation of all the loggers.
*
* @param debugMode whether to log in debug mode
*/
internal fun setupLogging(debugMode: Boolean) {
RootLogger.getRootLogger().level = if (debugMode) Level.DEBUG else Level.INFO
LogManager.getCurrentLoggers().asSequence().forEach { (it as Logger).setAppender() }
}
/**
* Add a custom console appender to this logger.
*
* @return this logger
*/
internal fun Logger.setAppender(): Logger = this.apply {
removeAllAppenders()
addAppender(ConsoleAppender(PatternLayout("(Thread %t) [%d] %p %c - %m%n")))
}