Experimenting with programmatic log levels.
This commit is contained in:
parent
d856f194ff
commit
09c174415b
@ -13,17 +13,20 @@ dependencies {
|
|||||||
// https://mvnrepository.com/artifact/org.apache.groovy/groovy
|
// https://mvnrepository.com/artifact/org.apache.groovy/groovy
|
||||||
implementation 'org.apache.groovy:groovy:4.0.7'
|
implementation 'org.apache.groovy:groovy:4.0.7'
|
||||||
|
|
||||||
|
// https://mvnrepository.com/artifact/info.picocli/picocli
|
||||||
|
implementation 'info.picocli:picocli:4.7.0'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logging
|
* Logging
|
||||||
*/
|
*/
|
||||||
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
|
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api
|
||||||
implementation 'org.slf4j:slf4j-api:1.7.36'
|
implementation 'org.apache.logging.log4j:log4j-api:2.19.0'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl
|
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl
|
||||||
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'
|
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
|
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
|
||||||
runtimeOnly 'org.apache.logging.log4j:log4j-core:2.19.0'
|
implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
@ -14,14 +14,56 @@ import com.jessebrault.ssg.text.MarkdownFrontMatterGetter
|
|||||||
import com.jessebrault.ssg.text.MarkdownTextRenderer
|
import com.jessebrault.ssg.text.MarkdownTextRenderer
|
||||||
import com.jessebrault.ssg.text.TextFileTextsProvider
|
import com.jessebrault.ssg.text.TextFileTextsProvider
|
||||||
import com.jessebrault.ssg.text.TextType
|
import com.jessebrault.ssg.text.TextType
|
||||||
import org.slf4j.Logger
|
import org.apache.logging.log4j.Level
|
||||||
import org.slf4j.LoggerFactory
|
import org.apache.logging.log4j.LogManager
|
||||||
|
import org.apache.logging.log4j.Logger
|
||||||
|
import org.apache.logging.log4j.core.config.Configuration
|
||||||
|
import org.apache.logging.log4j.spi.LoggerContext
|
||||||
|
import picocli.CommandLine
|
||||||
|
|
||||||
class StaticSiteGeneratorCli {
|
import java.util.concurrent.Callable
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(StaticSiteGeneratorCli)
|
@CommandLine.Command(
|
||||||
|
name = 'ssg',
|
||||||
|
mixinStandardHelpOptions = true,
|
||||||
|
version = '0.0.1-SNAPSHOT',
|
||||||
|
description = 'Generates a set of html files from a given configuration.'
|
||||||
|
)
|
||||||
|
class StaticSiteGeneratorCli implements Callable<Integer> {
|
||||||
|
|
||||||
|
private static final Logger logger = LogManager.getLogger(StaticSiteGeneratorCli)
|
||||||
|
|
||||||
|
static class LogLevel {
|
||||||
|
@CommandLine.Option(names = ['--info']) boolean info
|
||||||
|
@CommandLine.Option(names = ['--debug']) boolean debug
|
||||||
|
@CommandLine.Option(names = ['--trace']) boolean trace
|
||||||
|
}
|
||||||
|
|
||||||
static void main(String[] args) {
|
static void main(String[] args) {
|
||||||
|
System.exit(new CommandLine(StaticSiteGeneratorCli).execute(args))
|
||||||
|
}
|
||||||
|
|
||||||
|
@CommandLine.ArgGroup(exclusive = true)
|
||||||
|
private LogLevel logLevel
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Integer call() throws Exception {
|
||||||
|
def context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false)
|
||||||
|
def configuration = context.getConfiguration()
|
||||||
|
def rootLoggerConfig = configuration.getRootLogger()
|
||||||
|
|
||||||
|
if (this.logLevel.info) {
|
||||||
|
rootLoggerConfig.level = Level.INFO
|
||||||
|
} else if (this.logLevel.debug) {
|
||||||
|
rootLoggerConfig.level = Level.DEBUG
|
||||||
|
} else if (this.logLevel.trace) {
|
||||||
|
rootLoggerConfig.level = Level.TRACE
|
||||||
|
} else {
|
||||||
|
rootLoggerConfig.level = Level.WARN
|
||||||
|
}
|
||||||
|
|
||||||
|
context.updateLoggers()
|
||||||
|
|
||||||
def markdownText = new TextType(['.md'], new MarkdownTextRenderer(), new MarkdownFrontMatterGetter())
|
def markdownText = new TextType(['.md'], new MarkdownTextRenderer(), new MarkdownFrontMatterGetter())
|
||||||
def gspTemplate = new TemplateType(['.gsp'], new GspTemplateRenderer())
|
def gspTemplate = new TemplateType(['.gsp'], new GspTemplateRenderer())
|
||||||
def gspPart = new PartType(['.gsp'], new GspPartRenderer())
|
def gspPart = new PartType(['.gsp'], new GspPartRenderer())
|
||||||
@ -51,6 +93,7 @@ class StaticSiteGeneratorCli {
|
|||||||
|
|
||||||
def ssg = new SimpleStaticSiteGenerator(config)
|
def ssg = new SimpleStaticSiteGenerator(config)
|
||||||
ssg.generate(new File('build'), globals)
|
ssg.generate(new File('build'), globals)
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
</Console>
|
</Console>
|
||||||
</Appenders>
|
</Appenders>
|
||||||
<Loggers>
|
<Loggers>
|
||||||
<Root level="trace">
|
<Root level="warn">
|
||||||
<AppenderRef ref="standard" />
|
<AppenderRef ref="standard" />
|
||||||
</Root>
|
</Root>
|
||||||
</Loggers>
|
</Loggers>
|
||||||
|
Loading…
Reference in New Issue
Block a user