I have a problem with logging in Solr. I want it not to write everything on standard output (I mean glassfish server.log). I want it to use log4j and to write its messages to separate file. I've created log4j.xml file but I don't know if I can add it to the .war file. I've tried external log4j.xml file and setting JVM option -Dlog4j.configuration=file:/{path_to_file} and it worked but only partially. I have some other applications installed on glassfish and all of them started to write to this file. Any help appreciated.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You have to switch Solr's slf4j to log4j, too. As far as I see, you have to patch the war.
If you are using ant, this snippet could possibly help you with patching it:
<project name="solr-war-patching" default="patch" basedir=".">
<target name="patch" description="Patches solr war file">
<unjar src="solr.war" dest="solr.war.folder"/>
<delete file="solr.war.folder/WEB-INF/lib/slf4j-jdk14-1.6.1.jar" />
<delete file="solr.war.folder/WEB-INF/lib/log4j-over-slf4j-1.6.1.jar" />
<copy file="slf4j-log4j12-1.6.1.jar" todir="solr.war.folder/WEB-INF/lib" />
<copy file="log4j-1.2.16.jar" todir="solr.war.folder/WEB-INF/lib" />
<jar destfile="solr_patched.war">
<fileset dir="solr.war.folder" includes="**/**.*" />
</jar>
</target>
</project>
You have to have the respective jar files for the sl4j api in the folder you call the script...
The log4j.xml can be placed outside the war within the respective app container folder.