Reputation: 25
I want to export the log of my app in a html file,until now the log is displayed on the console of eclipse. in all my classes logs are defined by private static Logger logger = Logger.getLogger (classname.class.getName ());
does anyone know how I can do this in java?
Upvotes: 0
Views: 2282
Reputation: 298233
Re-configure a particular logger:
private static final Logger LOGGER
= Logger.getLogger(ClassName.class.getName());
static
{
try
{
LOGGER.addHandler(new FileHandler("mylog.xml"));
// if you don’t want additional console output:
LOGGER.setUseParentHandlers(false);
} catch(IOException ex)
{
throw new ExceptionInInitializerError(ex);
}
}
Or change the global configuration:
Create a properties file like this:
handlers=java.util.logging.FileHandler
java.util.logging.FileHandler.pattern=mylog2.xml
# add more options if you like
Run your application with -Djava.util.logging.config.file=<path to the file above>
.
In either case:
Study http://docs.oracle.com/javase/7/docs/api/java/util/logging/LogManager.html and http://docs.oracle.com/javase/7/docs/technotes/guides/logging/overview.html
Upvotes: 1
Reputation: 16999
You may do that using Log4j or some library.
You can export as XML for example with http://logging.apache.org/chainsaw/
There must be something similar with HTML, have a look at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/HTMLLayout.html
Upvotes: 0