Configure Logging for an Embedded Gateway
The default logging configuration for embedded Gateway uses the runtime logging tool log4j, and log4j logging is configured using the XML file log4j-config.xml in GATEWAY_HOME/conf/
. You can make the following modifications to this configuration:
- You can change where the embedded Gateway looks for the XML file in cases where you want to store your log4j XML file in a location outside of the default directory of the Gateway.
- You can change the file the embedded Gateway uses when you want the logging data configured using a different XML file.
- You can also override the default logging setting for the embedded Gateway to use a different logging system.
Before You Begin
This procedure is part of Embed Kaazing Gateway in Your Java Application:
- Set Up Your Development Environment
- Create the Embedded Gateway Object
- Use the Embedded Gateway Methods
- Configure Logging for an Embedded Gateway
- Monitor and Manage an Embedded Gateway
- Troubleshoot Your Embedded Gateway
To Override the Default Log4j Logging Settings
Log4j settings are configured using an XML file named log4j-config.xml and stored by default in the directory GATEWAY_HOME/conf/
. You can configure the embedded Gateway to use a different directory and file by modifying the fully qualified path to a log4J configuration file. To configure a different log4j file for the embedded Gateway, use the LOG4J_CONFIG_PROPERTY property as follows:
Properties props = new Properties(); props.setProperty("LOG4J_CONFIG_PROPERTY", "/home/kaazing/log4j.xml"); /* Windows Example * props.setProperty("LOG4J_CONFIG_PROPERTY", "C:\kaazing\conf\log4j.xml"); */ Gateway gateway = GatewayFactory.createGateway(); gateway.setProperties(props);
Note: See Apache log4j™ for more information about configuring log4j.
To Use A Different Logging System
If you want to use a logging system other than log4j (the default), you can override the default logging configuration for the embedded Gateway. You can use any logging system that supports the Simple Logging Facade for Java (SLF4J).
To override the default logging configuration of the embedded Gateway:
-
Set the OVERRIDE_LOGGING property to true. For example:
Properties props = new Properties(); props.setProperty("OVERRIDE_LOGGING", "true"); Gateway gateway = GatewayFactory.createGateway(); gateway.setProperties(props);
-
Replace the log4j SLF4J bindings on your classpath with the new SLF4J framework. For example, to switch from log4j to java.util.logging, replace slf4j-log4j12-1.5.2.jar (located in
GATEWAY_HOME/lib/
) with slf4j-jdk14-1.6.4.jar.
Note: For more information, see Binding with a logging framework at deployment time in the SLF4J user manual.