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_TYPES
HELPER_TAG_TYPES
configuration
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() |
allowedTagTypes
getRequiredHashKeys, numberOfRequiredHashEntries, numberOfRequiredParameters, validate
append, convertAndAppend, convertValue, init, isSection, isUnescapeVariable, isVariable
checkNotInitialized, init
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getConfigurationKeys, init
public 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)
Helper
protected Set<String> getSupportedHashKeys()
getSupportedHashKeys
in class BasicHelper
*
to
allow any hash keyspublic static LogHelper.Builder builder()
Copyright © 2017. All rights reserved.