How to make general Apache log in a specific disk log file

I am using Apache Common Logging in a desktop application.

private static final Log log = LogFactory.getLog(Utils.class);

      

How can I direct Apache Common Logging to write to the disk log file when I execute

log.error(null, exp);

      

Thanks.

+2


a source to share


2 answers


Commons logging is basically a wrapper around Java logging (java.util.logging) or log4j libraries. You will need to configure whatever base library you are using.

In your example, if I was using log4j (and I usually prefer it in the Java logging system), I would use something like:

log4j.logger.com.mypackage.Myclass = ERROR, FILEA



To specify a file to output to.

It would be helpful to read the introduction to log4j if you haven't already.

+1


a source


Define appenders in your config file. For a Log4J sample take a look at http://www.java2s.com/Code/Java/Language-Basics/Examplelog4jConfigurationFile.htm



For registration in Java, see http://www.oracle.com/technology/pub/articles/hunter_logging.html

+1


a source







All Articles