|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
log4j |
« View previous topic :: View next topic » |
Author |
Message
|
chris boehnke |
Posted: Mon Apr 27, 2015 8:46 am Post subject: log4j |
|
|
 Partisan
Joined: 25 Jul 2006 Posts: 369
|
Hi All,
I an trying to use log4j to log only exceptions.
I have placed the log4j jar in shared classes and used the logger.error to capture the exception.
I placed the log4j.xml file in the current project.
Do I need to refer this properties file in my JCN or anyother place?
THanks |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Apr 27, 2015 8:49 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You should use java.util.logging instead.
No need to manage external jar files that way.
If you want to configure log4j, then you need to point it at the correct properties file. |
|
Back to top |
|
 |
chris boehnke |
Posted: Mon Apr 27, 2015 1:12 pm Post subject: |
|
|
 Partisan
Joined: 25 Jul 2006 Posts: 369
|
I placed the log4j.xml in wsrr folder and was able to see the log file in the folder i specified in the log4j.xml file.
But I the file looks emplty. I am not sure if I went wrong anywhere. Below is the code i used. I am using all ESQL compute nodes. This logging node is only JCN I am using.
Below is my code and log4j xml file. Need your help.
Quote: |
public class LoggingNode extends MbJavaComputeNode {
public static final Logger logger = Logger.getLogger(LoggingNode.class);
@Override
public void evaluate(MbMessageAssembly assembly) throws MbException {
// TODO Auto-generated method stub
MbOutputTerminal out = getOutputTerminal("out");
MbMessage outmessage = new MbMessage(assembly.getMessage());
MbMessage outlocal = new MbMessage(assembly.getLocalEnvironment());
MbMessageAssembly assemblyout = new MbMessageAssembly(assembly, outlocal, assembly.getExceptionList(), outmessage);
try{
MbElement exceptionlist = assembly.getExceptionList().getRootElement();
String exceptionliststr = exceptionlist.toString();
throw new MbUserException("LoggingNode","evaluate","WMBv8","1001","Exception raised in java node" , new String [] {exceptionliststr });
} catch (MbException mbe) {
// Actually rarely happens
logger.error("In Logging component, encounted MbException:");
logger.error(mbe);
mbe.printStackTrace();
} catch (Exception e) {
// Actually rarely happens
logger.error("In Logging component, encounted Exception:");
logger.error(e);
// Need this if log4j isn't set up correctly (e.g. log4j.xml is
// missing)
e.printStackTrace();
}finally{
out.propagate(assemblyout);
}
}
} |
Quote: |
log4j.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="DefaultLoggerAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:\\usr\\local\\applogs\\log4japplication1.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="5MB"/>
<param name="MaxBackupIndex" value="3"/>
</appender>
<root>
<appender-ref ref="DefaultLoggerAppender"/>
<level value="error"/>
</root>
</log4j:configuration> |
[/quote] |
|
Back to top |
|
 |
sudhanshus |
Posted: Tue Apr 28, 2015 12:53 am Post subject: |
|
|
Novice
Joined: 28 Oct 2013 Posts: 19
|
My suggestion:-
Put the log4j.properties file anywhere you like and create a configurable service and save the path there.
Now at the application startup, read the location of the properties file and initialize your logger. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|