简体   繁体   中英

How can I get the log-entries in my server.log file to print out on a jsf page

I'm using jboss 7 and i have a server application with a db tier, a business tier and a web tier with some jsf pages. In my application i'm using the logger "org.slf4j.Logger" on different tiers to log some warning and errors to a log file.

My question is how can I get the log-entries in my server.log file to print out on a jsf page ?

I don't want to read the file on ...jboss-as-7.1.1.Final/standalone/log directly because my application may run on different platforms...

Log into a database instead and serve the contents from there. No more relying on a specific directory (although you'll need a database).

Not the prettiest solution but what worked for me which also includes some debug was:

String pathToJSF = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/");
System.out.println("Real Path is: " + pathToJSF);
String fileSeparator = File.separator;
System.out.println("JBoss log directory is: " + pathToJSF.substring(0, pathToJSF.indexOf("standalone" + fileSeparator) + ("standalone" + fileSeparator).length()) + "log" + fileSeparator);
String jbossLogFile = pathToJSF.substring(0, pathToJSF.indexOf("standalone" + fileSeparator) + ("standalone" + fileSeparator).length()) + "log" + fileSeparator + "server.log";

This worked on windows with the following debug output:

Real Path is: C:\jboss-eap-7.1.0_non_community\jboss-eap-7.1\standalone\deployments\My.ear\My.war
JBoss log directory is: C:\jboss-eap-7.1.0_non_community\jboss-eap-7.1\standalone\log\

Also of note, this only works with JBoss EAP 6 or greater as I'm specifying/looking for "standalone" which didn't exist in previous JBoss versions. This may not be good to do it this way, but I did have a need to grab the servers log file and make it available and included in a downloadable zip file

Now reading the file and displaying it in the JSF page I leave up to you as I'm pretty sure you know how to do that! This was also tested on linux

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM