MyApp example (1 of 4)
|
// Import log4j classes. import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; public class MyApp { // Define a static logger variable so that it references // the Logger instance named "MyApp". static Logger logger = Logger.getInstance(MyApp.class); public static void main(String[] args) { // Set up a simple configuration that logs on the console. PropertyConfigurator.configure(args[0]); logger.info("Entering application."); Bar bar = new Bar(); bar.doIt(); logger.info("Exiting application."); } } |
The previous MyApp example always outputs the same log
information. Fortunately, it is easy to modify MyApp so
that the log output can be controlled at run-time.
The second version of MyApp instructs
PropertyConfigurator to parse a configuration file and
set up logging accordingly.
| GET THE DOCS DIRECTLY FROM THE DEVELOPER |
| For up to date and detailed log4j documentation directly from the developer please consider The complete log4j manual. |