We do a lot of trace logging in our WebSphere application and would like to separate some timing information in a separate log file.
Usually we import:
import java.util.logging.Level;
import java.util.logging.Logger;
And then declare:
private static final Logger logger = Logger.getLogger(Myclass.class.getName());
And then log:
logger.info("now logging...");
What is the simplest way of doing that?
You can use Apache logging services to create logs outside Websphere Application Server. Download log4j jar from here. This is a stable version of jar we have used. Add this jar to your application build path/class path/libraries. Add log4j.properties file under your src folder (empty package). log4j.properties will contain following lines:
You can change the log level as per environment instead of DEBUG(Production should use INFO or ERROR). Then add a class NewLogForEachRunFileAppender in com.logging package with following code.
Then your class (e.g., MyClass) in which you want to do logging should contain code like this:
Now build and run your application. Once you will call the showLogging() method of MyClass, it will create a log file with name
at path
Sample logs will be: