Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You don't do it in the Java main class, although it might be possible. You need to modify the log4j.properties.</p> <p>There is a root appender that should already appear in the property file. Set the level to DEBUG and you should see every log message. I recommend defining a fileappender first though. That way you can use your favorite text editor to browse the log messages.</p> <p>You should define the conversion pattern for the PatternLayout of your appender. For example:</p> <pre><code>log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n </code></pre> <p>Try adding the code below to your main class</p> <pre><code>import org.apache.log4j.BasicConfigurator; </code></pre> <p>In main():</p> <pre><code>BasicConfigurator.configure(); </code></pre> <p>This will use a simple configuration which should output all log messages to the console. Accourding to the <a href="http://logging.apache.org/log4j/1.2/manual.html" rel="nofollow">Apache logging manual</a>, you can send in the name of a config file as a parmeter like so:</p> <pre><code> import com.foo.Bar; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; public class MyApp { static Logger logger = Logger.getLogger(MyApp.class.getName()); public static void main(String[] args) { // BasicConfigurator replaced with PropertyConfigurator. PropertyConfigurator.configure(args[0]); logger.info("Entering application."); Bar bar = new Bar(); bar.doIt(); logger.info("Exiting application."); } } </code></pre> <p>I'm assuming the logger jar is in the classpath. I don't know about the apache logging framework but Log4J would send a message to the console (or stderr) about not finding the config file, and it could be easily overlooked depending on what else is sent to stdout. Also, (again for log4j) the directory the property file was in had to be in the CLASSPATH as well.</p> <p>It occurs to me to double check the expected name of the logfile. Log4J uses log4j.properties but is that what the Apache framework expects? Either way, you can declare the name of the config file when the logger is instantiated. Not sure what the methodname is though.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload