Gatschet
Gatschet

Reputation: 1537

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...

Upvotes: 0

Views: 703

Answers (2)

JGlass
JGlass

Reputation: 1467

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

Upvotes: 0

Kayaman
Kayaman

Reputation: 73558

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

Upvotes: 1

Related Questions