Here is a screen-shot of my application's logging component:
The tables are rendered using the JMesa data grid, which works very nicely. The tables are paginated and the columns are sortable as well as filterable. Furthermore, the table is refreshed via AJAX using the jQuery JavaScript library.
On this page you can:
- View your log files
- Download the logfile as text file
- View the configured loggers
- View all available logger
- Set logging levels for any of the available loggers
Although I originally used Log4j to retrieve the required logging data, the conversion over to Logback has been fairly straightforward. Here is one of the methods that interacts with logback and returns a collection of loggers:
public static List <ch.qos.logback.classic.logger> getLoggers(boolean showAll) {Anyway if you look for something similar for your own application, you can download all the relevant source code here. Please be aware that the archive is not a full demo application but rather a couple of source files cobbled together. If you rather like to see an entire buildable demo application, just let me know.
final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
final Listloggers = CollectionUtils.getArrayList();
for (ch.qos.logback.classic.Logger log : lc.getLoggerList()) {
if(showAll == false) {
if(log.getLevel() != null || LoggingUtil.hasAppenders(log)) {
loggers.add(log);
}
} else {
loggers.add(log);
}
}
return loggers;
}
3 comments:
Thanks for this! I used to do the exact same thing with log4j, but was having trouble figuring it out for SLF4J/logback. Very helpful.
Thanks for the feedback!
Thanks for the example. I wrote my own version from the ground up using Spring MVC but borrowed the idea from you.
Post a Comment