简体   繁体   English

如何获取server.log文件中的日志条目以在jsf页面上打印出来

[英]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. 我正在使用jboss 7,并且我有一个具有db层,业务层和带有一些jsf页面的Web层的服务器应用程序。 In my application i'm using the logger "org.slf4j.Logger" on different tiers to log some warning and errors to a log file. 在我的应用程序中,我使用不同层的记录器“ org.slf4j.Logger”将一些警告和错误记录到日志文件中。

My question is how can I get the log-entries in my server.log file to print out on a jsf page ? 我的问题是如何获取server.log文件中的日志条目以在jsf页面上打印出来

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... 我不想直接在... jboss-as-7.1.1.Final/standalone/log上读取文件,因为我的应用程序可能在不同的平台上运行...

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: 这在Windows上具有以下调试输出起作用:

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. 还要注意的是,这仅适用于JBoss EAP 6或更高版本,因为我要指定/寻找“独立”版本,而该版本在以前的JBoss版本中不存在。 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 这样做可能不是一件好事,但是我确实需要获取服务器日志文件并使之可用并包含在可下载的zip文件中。

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! 现在阅读文件并将其显示在JSF页面中,由我决定,我确定您知道该怎么做! This was also tested on linux 这也在Linux上进行了测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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