如何在IBM Websphare Liberty服务器中生成特定于应用程序的日志,我正在使用SLF4j,message.log和console.log的更新正常,但是未生成特定于应用程序的日志。 如果可以使用Log4j解决日志记录问题,那么它也将对我有用。
尝试将log4j2文件显式加载到静态块中,并且还放置在资源文件夹中,两者均无效。
可以查看自由服务器日志,但根本不会生成应用程序日志。
答案 0 :(得分:1)
看不到log4j日志的根本原因通常是因为classloader未拾取log4j2配置文件。您可以在这里选择一些方法来解决您的问题。
您可以访问IBM网站,以查找Liberty安装中$ {shared.config.dir}和$ {server.config.dir}的确切位置。 at here
<library id="log4jConfig">
<folder dir="/{directory containning log4j config file}" scanInterval="5s" />
</library>
<webApplication id="myapp" location="myapp.war" name="My App"/>
<classloader commonLibraryRef="log4jConfig"/>
</webApplication>
在jvm.options文件内设置为JVM参数 -Dlog4j.configurationFile = file:/path/to/log4j2.xml
将其打包在src / main / resources下的maven应用程序war文件中
答案 1 :(得分:0)
从我的应用程序类或入口点开始,此漏洞修复对我有效,使用下面的代码重新加载slf4j配置。
私有静态最终org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(theClassfromwheregeneratinglogs.class);
static {
try {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
// Call context.reset() to clear any previous configuration, e.g. default
// configuration. For multi-step configuration, omit calling context.reset().
context.reset();
configurator.doConfigure("/appserver/wlpusr/servers/applogs/logback.xml"); //This will reload the slf4j configuration from the given file location.
} catch (JoranException je) {
// StatusPrinter will handle this
}}