From c35d7794d8ed3265f09f3fdf4b76836a2c17ccc1 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 23 Feb 2016 18:16:41 +0100 Subject: [PATCH] Minor: make BriefLogFormatter.initVerbose take a set of flags saying what logging to activate vs silence. --- src/main/kotlin/core/utilities/Logging.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/core/utilities/Logging.kt b/src/main/kotlin/core/utilities/Logging.kt index 865cf135f6..b6a5b9a2fb 100644 --- a/src/main/kotlin/core/utilities/Logging.kt +++ b/src/main/kotlin/core/utilities/Logging.kt @@ -71,12 +71,22 @@ class BriefLogFormatter : Formatter() { loggerRefs.add(logger) } - fun initVerbose(vararg packages: String) { + /** + * Takes a set of strings identifying logger names for which the logging level should be configured. + * If the logger name starts with a + or an ordinary character, the level is set to [Level.ALL]. If it starts + * with a - then logging is switched off. + */ + fun initVerbose(vararg loggerNames: String) { init() loggerRefs[0].handlers[0].level = Level.ALL - for (spec in packages) { - val logger = Logger.getLogger(spec) - logger.level = Level.ALL + for (spec in loggerNames) { + val (name, level) = when (spec[0]) { + '+' -> spec.substring(1) to Level.FINEST + '-' -> spec.substring(1) to Level.OFF + else -> spec to Level.ALL + } + val logger = Logger.getLogger(name) + logger.level = level loggerRefs.add(logger) } }