This code sample demonstrates how to create a stand-alone Logger with output sent to a file.
About this task
This sample uses the java.util.logging.Logger object, sets the logger to the
ManagedConnectionFactory object and the log level to FINEST:
Procedure
-
In the application, create a java.util.logging.Logger object and a FileHandler, pass the
output file to the FileHandler, set the logger to the ManagedConnectionFactory object, and set
the log level:
com.ibm.connector2.ims.ico.IMSManagedConnectionFactory mcf =
new com.ibm.connector2.ims.ico.IMSManagedConnectionFactory();
mcf.setHostName("yourHostName");
mcf.setDataStoreName("yourDataStore");
mcf.setPortNumber(new Integer(yourPortNumber));
// Create a file logger
Logger logger = Logger.getLogger("myLogger");
FileHandler fh = new FileHandler("output.txt");
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
logger.addHandler(fh);
// Set the file logger to the IMSManagedConnectionFactory object
// Set log level to finest
LogUtils logUtils = new LogUtils(logger, "log", "yourProduct", "yourVersion");
mcf.setLogUtil(logUtils);
mcf.getLogUtil().setLoggingLevel(Level.FINEST);
connFactory = (ConnectionFactory) mcf.createConnectionFactory();
-
Add your other code for the application.
-
Run the application.
Results
As the application runs, information is logged to the output.txt
file.