Channels
A channel is like a logger except that it does not has targets. Such a channel can either be on or off. You can use these channels for special logging requests like logging all sql statements in your application. Rather then using a logger with a specific target it is easier and even more obvious when you use a channel for this.
The XML
Here is an example of how to define a channel in the log configuration:
<channel name="sql_statements">
<mode>on</mode>
<generator-name>TestGenerator</generator-name>
</channel>
The mode can be on or off. The
generator-name must be a reference to a
generator defined in the log configuration.
Using a channel
Using a channel in your code is simple:
import org.jzonic.jlo.*;
public class ChannelDemo {
private static final Channel channel = LogManager.getChannel("sql_statements");
public static main(String[] args) {
channel.log("Hello world!");
System.exit(0);
}
}
Special channels
There is one channel defined for each target. These are build-in channels and they are switched off by default. Every log request for a certain target will be processed by the specific channel before it is handled by the processor. So no matter which logger you use every logging request with the target info will be handled by the channel named info as well. This way you can for example log all exceptions that are logged with the target fatal to a different file. Defining a build-in channel looks like this:
<channel name="info">
<mode>on</mode>
<generator-name>TestGenerator</generator-name>
</channel>
Or you can use a channel for all exceptions and serious errors:
<channel name="fatal">
<mode>on</mode>
<generator-name>MailGenerator</generator-name>
</channel>
This example assumes that you are using the fatal target to log any exceptions and serious errors.