Reputation: 797
Is there a MEL expression to find the log level and store it in a string variable. I searched Google but didn't find it. Can any one help me?
Upvotes: 0
Views: 158
Reputation: 5115
There is no way of doing such thing, for a number of reasons. First there is no such thing as a loglevel but a combinations of log levels for packages or classes and a default log level, then each appender will have a minimum log level too, etc.
Also Mule tipically use SLF4J but not necesarily all code will. To make things complicated, in the soon to be released 3.6 the logging system has changed quite a bit.
If I had to do that I would probably have your log4j.properties as a maven processed resource that had the level set and then also would have a property file that mule should use as a property placeholder that will have the property also set as a processed resource.
Upvotes: 0
Reputation: 496
Through MEL, you can access a logger using
#[org.apache.commons.logging.LogFactory.getLog(loggerName)]
The Log interface does not contain any direct method to obtain its level, but you can know if a certain level is active or not. So you can use the following expression to obtain a logger level in MEL:
#[log = org.apache.commons.logging.LogFactory.getLog(loggerName); return log.isTraceEnabled() ? "TRACE" : log.isDebugEnabled() ? "DEBUG" : log.isInfoEnabled() ? "INFO" : log.isWarnEnabled() ? "WARN" : log.isErrorEnabled() ? "ERROR" : log.isFatalEnabled() ? "FATAL" : "OFF"]
Upvotes: 1