In one of codes I am using Jetty. I am using the Jetty jar and imports the Classes from my Java code.
Jetty's default log level is INFO if not configured specifically. We can enable DEBUG mode by code. The logger seems to be a log4j one.
org.mortbay.log.Logger jettyLogger = org.mortbay.log.Log.getLog();
jettyLogger.setDebugEnabled(true);
Assume I haven't added this to the code. And now I want to enable logging by some other method. Can I do this using a log4j configuration?
Here's the Jetty documentation page on how to use it's logger.
You should just be able to use a standard log4j.properties file if you're using log4j as your logging implementation
Add this to your log4j.xml file
<category name="org.mortbay">
<priority value="debug" />
</category>
Related
In a java program, I am using log4j2 for my (debug) output. When using a third party libary, I would like to disable the log output from these libraries. How can I do that?
Actually this seems quite simple to me but I could not find a solution for it. I can't be the only one looking for this?
An example of turning off logging in log4j 1.x was to add the following xml tag into log4j.xml. The category name is the package path to the root of the library you want to ignore logging from. For example to ignore log4j logging from the apache tiles library you would use the following:
<category name="org.apache.tiles">
<priority value = "off" />
</category>
With Weblogic 11g I have done the following:
1 Created log4j.xml file where I created a new appender:
<appender name="WEBLOGIC" class="weblogic.logging.log4j.ServerLoggingAppender">
<param name="Threshold" value="ERROR"/>
</appender>
<root>
<priority value="WARN"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
<appender-ref ref="WEBLOGIC"/>
</root>
2 Updated the ${DOMAIN_HOME}/bin/setDomainEnv.sh script with these changes:
LOG4J_CONFIG_FILE="${DOMAIN_HOME}/config/log4j.xml"
if [ "${LOG4J_CONFIG_FILE}" != "" ] ; then
JAVA_PROPERTIES="${JAVA_PROPERTIES} Dlog4j.configuration=file:${LOG4J_CONFIG_FILE}"
export JAVA_PROPERTIES
fi
JAVA_OPTIONS="${JAVA_OPTIONS} ${JAVA_PROPERTIES} -Dweblogic.log.Log4jLoggingEnabled=true -Dwlw.iterativeDev=${iterativeDevFlag} -Dwlw.testConsole=${testConsoleFlag} -Dwlw.logErrorsToConsole=${logErrorsToConsoleFlag}"
3 Copied the log4j jars to the domain/lib
cp ./wlserver_10.3/server/lib/wllog4j.jar user_projects/domains/my_domain/lib/
cp ./wlserver_10.3/server/lib/consoleapp/APP-INF/lib/log4j-1.2.8.jar user_projects/domains/my_domain/lib/
4 Starts the AdminServer, but I get this error:
java.lang.ClassCastException:
weblogic.logging.log4j.ServerLoggingAppender cannot be cast to
org.apache.log4j.Appender
Keep step 1 and remove changes done in other steps.
Now copy the log4j.xml to $DOMAIN_HOME/lib folder. This will keep your log4j.xml in the server's classpath and the server will use this log4j.xml as its log4j configuration. No additional changes are required.
In setDomainEnv.xml file, please add the set log4j.xml location as below:
set LOG4J_CONFIG_FILE=C:\bea\user_projects\domains\dev\lib\log4j.xml
if NOT "%LOG4J_CONFIG_FILE%"=="" (
set JAVA_PROPERTIES=%JAVA_PROPERTIES% -Dlog4j.configuration=file:%LOG4J_CONFIG_FILE%
)
What you have to see is if despite the warning that you get, if the ServerLogging is effectively not working on your appliction on your domain.
Probably not even there since you are only copying the log4j to the domain/lib folder but not the wllog4j.jar.
So your setup looks like is doomed not to work in any case.
To me, It looks to me that you are undergoing Class Loader Vodoo Messup.
(1) You set a global log4j properties file for the entire app server.
(2) it looks like weblogic console app is itself a ear and it bundles its own LOG4J implementation library, which you are copying into your domain.
When the console app runs, it must for sure make use of Log4j and the class loader loading the Log4j Appender definition is most likely a level lower than the class loader that knows about the ServerLoggin bridge adapter.
I am beting its for reason like this that weblogic is geting rid of LOG4j in future gnerations of the product.
They have too many class loader issues - JUL logging you have the APP class loader behind the core classes - such as Handlers/Adapters.
Anyway.
(3) When weblogic runs, namley when it bootstraps the console it probably runs some sort class loader that gives a level of isolation to the libs bundled in the applicaiton and it sees:
Oh! How nice, LOG4j is here, leets initialize it.
Second, LOG4j bootstraps and hits head on your log4j.properties where you put the server logging appender in there - cross cutingly for everybody (including the weblogic application console).
He goes hunting for this library and where does it find it?
One of them, the wllog4j.jar he finds somewhere in the weblogic generic container libraries. While the base core classes of Log4j he finds a level lower in the domain configuration or in the EAR configuraiton of the console applicaiton.
This is not good.
Try the following:
(a) go into the weblogic console app, go to the Meta Inf folder and re-write the weblogi-application.xml
It will have a prefer applicaiton packages that looks like this:
org.apache.log4j.*</package-name--> <---- here I've commented this line.
If you comment the above line, the application class loader will search for log4j libraries in the highest parent that knows about these classes.
So if you put at the same level where your ServerLogger is found you should be fine.
(b) Pug the log4j implementation library at the same level where the wllog4j.jar will be found.
Check if you still get the casting exceptions.
Be very careful when you make server wide cross cuting configurations.
Good luck.
jsf validation gives this massage
INFO [javax.enterprise.resource.webcontainer.jsf.renderkit] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed. sourceId=null[severity=(ERROR 2), summary=(Your User Name or Password is incorrect.), detail=(Your User Name or Password is incorrect.)]
But my login.xhtml page shows Your User Name or Password is incorrect. massage. what is wrong with this.
EDIT: I wanted to prevent printing this massage in console
Thanks in advance
EDIT
In case you want message to not to be printed in logs... turn off the logging for javax.enterprise.resource.webcontainer.jsf.renderkit. I believe you are using log4j. We have turned it off with following entry in your jboss-log4j.xml:
<category name="javax.enterprise.resource.webcontainer.jsf.renderkit">
<priority value="OFF" />
</category>
If it's not log4j It depends on what logging library you are using. Try setting the
default logging level to ERROR or FATAL. Otherwise, just set the logging level for javax.enterprise.resource.webcontainer.jsf.renderkit to something higher than INFO.
So it is this other logging library that you need to configure in order to control what gets output.
If your WEB-INF/lib directory contains log4j.jar, then you will need to add a log4j.properties or log4j.xml file into your WEB-INF/classes dir to configure log4j. See the log4j project for further instructions.
If your WEB-INF/lib directory does not contain log4j.jar then this is probably being logged via the java.util.logging implementation provided in the java standard libraries. So you will need to configure that; see the javadoc for the java.util.logging classes for details.
Hope this gives you enough information.
I am new to JavaEE SSH environment, and currently I use log4j as my application's log system. But the problem is that if I set the log output level at DEBUG there are too many console output in MyEclipse, switch the output level to WARN will reduce the amount of the messages but also lost some information I interested in. So my question is how to let the log4j ONLY output ALL the log message generated by the Java file I am editing and DO NOT output ANY messages generated by others.
Assuming you are configuring log4j with a log4j.properties file, you can set a specific class or package to a different level like this:
log4j.logger.com.foo.MyClass=DEBUG
See http://logging.apache.org/log4j/1.2/manual.html for more introductory log4j stuff.
http://logging.apache.org/log4j/1.2/manual.html
You can configure the log-level of every Logger you created via Logger.getLogger("org.springframework") . You must search the configuration file for log4j.
Example for XML (from http://en.wikipedia.org/wiki/Log4j):
...
<logger name="org.springframework">
<level value="info"/>
</logger>
<!--
everything of spring was set to "info" but for class
PropertyEditorRegistrySupport we want "debug" logging
-->
<logger name="org.springframework.beans.PropertyEditorRegistrySupport">
<level value="debug"/>
</logger>
Hope that helps.
if you are running in the unix/linux environment, you can tail and grep the log file what exactly you are looking for. this is more flexible than modifying log4j configuration and much more powerful
I had the same issue whereby my log4j debug logging was being overwhelmed by Spring debugging in my JUnit unit tests (in Eclipse). I got around this by adding the following to my log4j properties file.
log4j.logger.org.springframework=FATAL
I have an EAR that is made up of two modules. Both expose services and share common code.
Imagine that the ear has a common.jar shared by a webservices.war and webapp.war.
I use log4j to log the activities. I would like to be able to have two log files (webservices.log and webapp.log) capturing the events that are specific to each of them plus all the stuff that is handled by the common.jar.
How should I configure my categories and my appenders to achieve this?
At the moment I have the following packages:
com.myapp for shared stuff
com.myapp.webservices for the webservices and
com.myapp.webapp for the webapp.
My problem is that I don't know how I can capture the com.myapp (common stuff) in both log files by using a single log4j configuration file.
I have tried setting up multiple configuration files but when JBoss would work OK Websphere would break and the other way round...
Thank you
You can keep log4j configuration anywhere you like, just make sure Logger is able to initialize the engine from the configuration file. I don't see any reason why one configuration file is not working for both Jboss and WebSphere. Could you be more specific on what is breaking?
You need to configure two file appenders named webservices and webapp in same log4j configuration files and using the package names redirect to the relevant appender.
<logger name="com.myapp.webservices">
<appender-ref ref="webservices" />
</logger>
<logger name="com.myapp.webapp">
<appender-ref ref="webapp" />
</logger>