Previous Page | Next Page

Using the Java Connection Factory

Logging Java Connection Factory Activity


Overview of Logging

If you connect by using the PlatformConnectionFactory class, then logging is handled by the Logging Service component of SAS Foundation Services. The logging context for a Java Connection Factory is "com.sas.services.connection". For more information about the Logging Service, see Modifying the Logging Service Configuration in the SAS Foundation Services: Administrator's Guide and com.sas.services.logging in the Foundation Services class documentation at http://support.sas.com/92api .

If you are connecting by using the ConnectionFactory class, then logging is handled by the java.util.logging package. The Java Connection Factory writes diagnostic and status messages to the console by default. These messages are useful for debugging or performance monitoring.

Note:    The following sections apply to the ConnectionFactory class only.  [cautionend]


Changing the Message Level

To change the types of messages that are logged, create a Logger object by using the Logger.getLogger() method in java.util.logging , and then use the setLevel() method to set the level of messages that the logger uses. The default message level is INFO .

The following code fragment specifies that detailed tracing messages should be logged in addition to the default messages:

import java.util.logging.*;
ConnectionFactoryManager cxfManager = new ConnectionFactoryManager();
ConnectionFactoryConfiguration cxfConfig = ...
String loggerName = cxfManager.getFactoryLoggerName(cxfConfig);
Logger logger = Logger.getLogger(loggerName);
logger.setLevel(Level.FINEST);

The following code fragment specifies that no messages are logged:

import java.util.logging.*;
ConnectionFactoryManager cxfManager = new ConnectionFactoryManager();
ConnectionFactoryConfiguration cxfConfig = ...
String loggerName = cxfManager.getFactoryLoggerName(cxfConfig);
Logger logger = Logger.getLogger(loggerName);
logger.setLevel(Level.OFF);


Logging to a File

To log messages to a file, create a FileHandler object by using the constructor method in java.util.logging and add it to your connection factory's Logger object.

The following code fragment specifies that verbose messages are logged to a file and console logging is disabled:

import java.util.logging;
ConnectionFactoryManager cxfManager = new ConnectionFactoryManager();
ConnectionFactoryConfiguration cxfConfig = ...
String loggerName = cfxManager.getFactoryLoggerName(cxfConfig);
Logger logger = Logger.getLogger(loggerName);
logger.setLevel(Level.FINEST);
FileHandler handler = new FileHandler("file-path");
handler.setLevel(Level.FINEST);
logger.addHandler(handler);
logger.setUseParentHandlers(false);

Note:      If you do not specify setUseParentHandlers(false) , then messages are sent to both the log file and the console.  [cautionend]

Previous Page | Next Page | Top of Page