









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The limitations of using system.out.println for application logging and introduces log4j as an alternative. Log4j is an open-source logging library that provides more advanced features such as multiple loggers, appenders, and layouts. It also allows for separating messages by domain, severity, and making one log in different formats. Instructions on how to install and use log4j.
Typology: Slides
1 / 15
This page cannot be seen from the preview
Don't miss anything!










System.out.println()
System.err.println()
^ Can t make one log in text format and another in XMLformat^ Can’t separate messages into separate logs by domain,subject, severity, who can fix, etc.^ LoggersLoggers are the things you work with in code to sendmessages to.^ AppendersAppenders are output destinations ``^ LayoutsLayouts are the formats that appenders use to writetheir output^ A logger is what your code interacts with to requestthat a message be logged.that a message be logged.^ It takes all message requests, regardless of level,severity, eventual destination, etc. ^ Internally every logger has a java-class-like name^^ Dots between words work like package and sub-package^ You declare loggers in your code then start loggingto them^ You do this using the^ If the logger specified does not exist it is automatically^ If the logger specified does not exist it is automaticallycreated `^ You generally pass the class (or name of the class) that isd^^ Before using your loggers you need to make surethe log4j engine is configuredthe log4j engine is configured^ Typically this is done by reading a properties file, butcan be done programmatically `^ Will discuss configuration in more depth in a minuteti^
&^ t i
l^
th d
// Creation & retrieval methods:public static Logger getRootLogger();public static Logger getLogger(String name);// printing methods:// printing methods:public void trace(Object message);public void debug(Object message);public void info(Object message);public void info(Object message);public void warn(Object message);public void error(Object message);public void fatal(Object message);p^
(O j^
g );
Fall 2010 cs
^ The logger will always accept your message^ However the logger might not always route it^ However, the logger might not always route itanywhere^ Where it goes is a function of^ the message severity^ the logger’s name `^ what appenders are attached to it