public class LogHelper extends BasicValueHelper
A simple log helper. There is a special LogHelper.Builder for convenience.
First register the helper instance:
MustacheEngineBuilder.newBuilder().registerHelper("log", LogHelper.builder().setDefaultLevel(Level.DEBUG).build()).build();
Than use the helper in the template:
{{log "Hello"}}
The message need not be a string literal:
{{log foo.message}}
You may also override the default log level:
{{log "" level="DEBUG"}}
And also use message parameters:
{{log "Number of items found: {}" items.size}}
Note that the final output will depend on the specified LogHelper.LoggerAdapter
and underlying logging framework configuration.
LogHelper.Level,
LogHelper.LoggerAdapter| Modifier and Type | Class and Description |
|---|---|
static class |
LogHelper.Builder |
static class |
LogHelper.Level
Log level.
|
static interface |
LogHelper.LoggerAdapter
Log event adapter.
|
static class |
LogHelper.Slf4jLoggerAdapter
A default adapter implementation for SLF4J.
|
VALUE_TAG_TYPESHELPER_TAG_TYPESconfiguration| Constructor and Description |
|---|
LogHelper(LogHelper.LoggerAdapter adapter,
LogHelper.Level defaultLevel,
boolean appendTemplateInfo) |
| Modifier and Type | Method and Description |
|---|---|
static LogHelper.Builder |
builder() |
void |
execute(Options options)
Execute the helper.
|
protected Set<String> |
getSupportedHashKeys() |
allowedTagTypesgetRequiredHashKeys, numberOfRequiredHashEntries, numberOfRequiredParameters, validateappend, convertAndAppend, convertValue, init, isSection, isUnescapeVariable, isVariablecheckNotInitialized, initclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetConfigurationKeys, initpublic LogHelper(LogHelper.LoggerAdapter adapter, LogHelper.Level defaultLevel, boolean appendTemplateInfo)
adapter - defaultLevel - appendTemplateInfo - If true, a template name and helper line will be appended to
each log messagepublic void execute(Options options)
Helperprotected Set<String> getSupportedHashKeys()
getSupportedHashKeys in class BasicHelper* to
allow any hash keyspublic static LogHelper.Builder builder()
Copyright © 2017. All rights reserved.