-
Notifications
You must be signed in to change notification settings - Fork 16
Feature/simple logging #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
0aa366c
606aacb
9e572bd
9014771
078b727
8bdaf0f
6a7d650
801484f
36ac26e
00c712a
053dfc9
351c76a
0733e11
2578f8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package org.utplsql.cli; | ||
|
|
||
| import ch.qos.logback.classic.Level; | ||
| import ch.qos.logback.classic.Logger; | ||
| import ch.qos.logback.classic.LoggerContext; | ||
| import ch.qos.logback.classic.encoder.PatternLayoutEncoder; | ||
| import ch.qos.logback.classic.spi.ILoggingEvent; | ||
| import ch.qos.logback.core.ConsoleAppender; | ||
| import com.zaxxer.hikari.HikariDataSource; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.utplsql.api.TestRunner; | ||
|
|
||
| class LoggerConfiguration { | ||
|
|
||
|
pesse marked this conversation as resolved.
|
||
| static void configure(boolean silent, boolean debug) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we use two parameters here? Are all 4 combination of their values valid? Maybe we should accept 3-valued enum?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reason is to make it easy to just pass the parameters of the RunCommand to the LoggerConfigurator.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should. If non flags are passed then default logging is enabled, if silent - non, if debug - debug. And then we end up with 3 levels, set on application level and non of other classes should think about it. Classes just log using appropriate log level (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I get you completely right. |
||
| if ( silent ) | ||
| configureSilent(); | ||
| else if ( debug ) | ||
| configureDebug(); | ||
| else | ||
| configureDefault(); | ||
| } | ||
|
|
||
| private static void configureSilent() { | ||
| Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); | ||
| root.setLevel(Level.OFF); | ||
| } | ||
|
|
||
| private static void configureDefault() { | ||
|
pesse marked this conversation as resolved.
Outdated
|
||
| Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); | ||
| root.setLevel(Level.INFO); | ||
|
|
||
| ((Logger) LoggerFactory.getLogger(HikariDataSource.class)).setLevel(Level.OFF); | ||
| ((Logger) LoggerFactory.getLogger(TestRunner.class)).setLevel(Level.ERROR); | ||
|
|
||
| setSingleConsoleAppenderWithLayout(root, "%msg%n"); | ||
| } | ||
|
|
||
| private static void configureDebug() { | ||
| Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); | ||
| root.setLevel(Level.DEBUG); | ||
|
|
||
| setSingleConsoleAppenderWithLayout(root, "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"); | ||
| } | ||
|
|
||
| private static void setSingleConsoleAppenderWithLayout( Logger logger, String patternLayout ) { | ||
| LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); | ||
|
|
||
| PatternLayoutEncoder ple = new PatternLayoutEncoder(); | ||
| ple.setPattern(patternLayout); | ||
|
|
||
| ple.setContext(lc); | ||
| ple.start(); | ||
|
|
||
| ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>(); | ||
| consoleAppender.setEncoder(ple); | ||
| consoleAppender.setContext(lc); | ||
| consoleAppender.start(); | ||
|
|
||
| logger.detachAndStopAllAppenders(); | ||
| logger.setAdditive(false); | ||
| logger.addAppender(consoleAppender); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.