Log levels determine results of log statements
The correlator supports the following log levels:
0 | OFF | No entries go to log files. |
1 | CRIT | Least amount of entries go to log files. |
2 | FATAL | | |
3 | ERROR | | |
4 | WARN | | |
5 | INFO | | |
6 | DEBUG | | |
7 | TRACE | Greatest amount of entries go to log files. |
You use log levels to filter out log strings. If the log level in effect is lower than the log level in the log statement the correlator does not send the string to the log file. For example, if the log level in effect is ERROR (3) and the log level in the log statement is DEBUG (6) the correlator does not send the string to the log file since the log level in effect is lower than the log level in the log statement.
Suppose that a string expression in a log statement executes an action or has side effects. In this situation, the correlator executes the log statement so that side effects always take place. However, if the log level in effect is lower than the log level in the log statement the correlator still does not send the string to the log file.
Here are some examples where the log level in effect is WARN:
log "foo bar" at CRIT; // Sends "foo bar" to the log file.
log "foo bar" at INFO; // Does not send anything to the log file.
log "foo" + "bar" + 12345.toString() at INFO;
// Does not send anything to the log file.
// The expression in the log statement is not evaluated as
// the log level is too low to send output to the log file,
// and the expression does not have side effects.
log "foo" + bar() + 12345.toString() at INFO;
// Does not send anything to the log file.
// Calls bar() since that action might have side effects,
// for example, the action could send an event.
Actions on events or monitors are assumed to have side effects. The
com.apama.epl.SideEffectFree annotation (see
Adding predefined annotations) can be added to an action definition to mark it as side effect free. Note that with this annotation, actions will only be called from log statements if the log statement would write to the log file. This is more compact than checking the log level before executing the log statement. If the action does in fact have side effects, then changing the log level can change the behavior of your program. It is recommended to only add the
SideEffectFree annotation on an action if a profile shows that a lot of time is spent in calling that action (premature optimizations add to program complexity for no benefit). Actions called via an action variable are always assumed to have side effects, as the EPL runtime does not know which action is invoked.
For more information on the profile, see
Profiling EPL Applications.
To determine the log level in effect, the correlator checks whether you set a log level for the following in the order specified below:
1. The monitor or event that contains the log statement.
2. A parent of the monitor or event that contains the log statement. The correlator starts with the immediate parent and works its way up the tree as needed.
3. The correlator.
The log level in effect is the first log level that the correlator finds in the tree structure. See
Setting logging attributes for packages, monitors and events. If the correlator does not find a log level, the correlator uses the correlator’s log level. If you did not explicitly set the correlator’s log level, the default is
INFO.
After the correlator identifies the applicable log level, the log level itself determines whether the correlator sends the log statement output to the appropriate log file as follows:
Log Level in Effect | For Log Statements With These Identifiers, the Correlator Sends the Log Statement Output to the Appropriate Log File | For Log Statements With These Identifiers, the Correlator Ignores Log Statement Output |
OFF | None | CRIT, FATAL, ERROR, WARN, INFO, DEBUG, TRACE |
CRIT | CRIT | FATAL, ERROR, WARN, INFO, DEBUG, TRACE |
FATAL | CRIT, FATAL | ERROR, WARN, INFO, DEBUG, TRACE |
ERROR | CRIT, FATAL, ERROR | WARN, INFO, DEBUG, TRACE |
WARN | CRIT, FATAL, ERROR, WARN | INFO, DEBUG, TRACE |
INFO | CRIT, FATAL, ERROR, WARN, INFO | DEBUG, TRACE |
DEBUG | CRIT, FATAL, ERROR, WARN, INFO, DEBUG | TRACE |
TRACE | CRIT, FATAL, ERROR, WARN, INFO, DEBUG, TRACE | None |
An advantage of this framework is that there is no performance penalty for having log statements that do not specify actions in your application. You control the overhead of executing such log statements by specifying the appropriate log level.