...
This will allow a configuration like the one shown below. log4j2 at the top level identifies the file as containing log4j properties. The element at the next level down is the name of the LoggerContext the enclosed properties apply to. A "*" as the LoggerContext name indicates the settings are the default values. Within that properties are grouped by the components they apply to. Note that the term "component" is used loosely here.
...
Code Block |
---|
{ "log4j2": { "My-App": { "JmsJNDI": { "enableJndienableJMS": "true" } "Script": { "enableLanguages": [ "Groovy", "JavaScript" ] } "Configuration": { "mergeStrategy": "com.acme.log4j.CustomMergeStrategy", "location": "classpath:log4j2-My-App.xml", "statusLoggerLevel": "debug" } }, "*": { "StatusLogger": { "defaultStatusLevel": "Info" } }} |
Of course, the equivalent would also be available as properties, although the property names will change from their current values
Code Block |
---|
log4j2.My-App.Jms.enableJndi=true
log4j2.My-App.Script.enableLanguages=Groovy,Javascript
log4j2.My-App.Configuration.mergeStrategy=com.acme.log4j.CustomMergeStrategy
log4j2.My-App.Configuration.location=classpath:log4j2-My-App.xml
log4j2.My-App.Configuration.statusLoggerLevel=debug
log4j2.*.StatusLogger.defaultStatusLevel=Info |
Using this format allows restrictions to be placed on plugins:
Code Block |
---|
@RequireProperty(component = "Lookup", property = "enableJndi", value = "true") @Plugin(name = "jndi", category = StrLookup.CATEGORY) public class JndiLookup extends AbstractLookup {} |
...
In the case of Scripting we would want the ScriptManager to be disabled unless one or more scripting language are enabled. In the case of the ScriptManager it is loaded by the ScriptManagerFactory in Log4j 2 3.x, which is loaded via ServiceLoader. The ScriptManager then locates all the ScriptEngines it can find. Each engine identifies the scripting languages it supports. If a matching language isn't specified in the properties than that engine would be discarded.
Log4j 2 3.x will also come with a file named log4j2.default.component.yml that declares the default values for all properties except for log4j2.debug and log4j2.contextSelector, whose values apply to all usages of Log4j in the JVM. The file below will be included in Log4j 2 to contain the default values.
Code Block |
---|
{
"log4j2": {
"*": {
"AsyncLogger": {
"exceptionHandler": "",
"ringBufferSize": "caclculate",
"waitStrategy": "Timeout",
"timeout": 10,
"sleepTimeNS": 100,
"retries": 200,
"synchronizeEnqueWhenFull": true,
"threadNameStrategy": "CACHED",
"queueFullPolicy": "",
"discardThreshold": "INFO",
"formatMsg": false
},
"Configuration": {
"location": "",
"mergeStrategy": "org.apache.logging.log4j.core.config.composite.DefaultMergeStrategy",
"configurationFactory": "org.apache.logging.log4j.core.config.ConfigurationFactory",
"clock": "org.apache.logging.log4j.core.util.SystemClock",
"level": "ERROR"
},
"GC": {
"enableThreadLocals": true,
"enableDirectEncoders": true,
"intialReusableMsgSize": 128,
"maxReusableMsgSize": 518,
"layoutStringBuilderMaxSize": 2048,
"unboxRingBufferSize": 32
},
"Jansi": {
"enabled": "true"
},
"JMX": {
"enabled": "false",
"notifyAsync": "calculate"
},
"JNDI": {
"enableContextSelector": "false",
"enableJdbc": "false",
"enableJMS": "false",
"enableLookup": "faslse"
},
"JUL": {
"loggerAdapter": "org.apache.logging.log4j.jul.ApiLoggerAdapter"
},
"LoggerContext": {
"logEventFactory": "org.apache.logging.log4j.core.impl.DefaultLogEventFactory",
"loggerContextFactory": "org.apache.logging.log4j.simple.SimpleLoggerContextFactory",
"shutdownHookEnabled": "true",
"shutdownCallbackRegistry": "org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry",
"stackTraceOnStart": false
},
"Message": {
"messageFactory": "org.apche.logging.log4j.message.ParameterizedMessagefactory",
"flowMessageFactory": "org.apache.logging.log4j.message.DefaultFlowMessageFactory"
},
"Script": {
"enableLanguages": []
},
"SimpleLogger": {
"showContextMap": false,
"showLogName": false,
"showShortLogName": true,
"showDateTime": false,
"dateTimeFormat": "yyyy/MM/dd HH:mm:ss:SSS zzz",
"logFile": "systemerr",
"logLevel": "ERROR",
"{loggerName}.level": "",
"statusLoggerLevel": "ERROR"
},
"StatusLogger": {
"defaultStatusLevel": "ERROR",
"statusLoggerLevel": "WARN",
"entries": 200,
"dateFormat": ""
},
"ThreadContext": {
"enabled": "true",
"enableMap": "true",
"enableStack": "false",
"inheritable": "false",
"garbageFree": "false",
"contextDataInjector": "org.apache.logging.log4j.core.ContextDataInjector"
},
"TransportSecurity": {
"trustStoreLocation": "",
"trustStorePassword": "",
"trustStorePasswordFile": "",
"trustStorePasswordEnvironmentVariable": "",
"trustStoreType": "trustStoreKeyManagerFactoryAlgorithm",
"keyStoreLocation": "",
"keyStorePassword": "",
"keyStorePasswordFile": "",
"keytorePasswordEnvironmentVariable": "",
"keyStoreType": "",
"keyStoreKeyManagerFactoryAlgorithm": ""
},
"UUID": {
"sequence": ""
},
"Web": {
"enableWebApp": "calculate"
}
}
}
} |