|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Using LOG4J API in ESQL |
« View previous topic :: View next topic » |
Author |
Message
|
balaji83it |
Posted: Thu Nov 01, 2012 6:21 am Post subject: Using LOG4J API in ESQL |
|
|
Acolyte
Joined: 20 Jul 2007 Posts: 72
|
Hello,
I downloaded IAM3 support pack for using log4j java API as part of ESQL. I do not want the node functionality. I only need the java API for log4j to log errors and warnings.
I followed the instructions as given in the IAM3.pdf file.
Iam giving the following code in my ESQL
Code: |
CREATE FUNCTION initLog4j( IN CONFIG_FILE_NAME CHARACTER )RETURNS BOOLEAN LANGUAGE JAVA
EXTERNAL NAME "com.ibm.broker.IAM3.Log4jNode.initLog4j";
CREATE FUNCTION log4j( IN COMPONENT_NAME CHARACTER,IN LEVEL CHARACTER,IN TEXT CHARACTER )RETURNS BOOLEAN LANGUAGE JAVA
EXTERNAL NAME "com.ibm.broker.IAM3.Log4jNode.log";
CREATE FUNCTION log4j_1_1( IN COMPONENT_NAME CHARACTER,IN LOGGER_NAME CHARACTER,IN LEVEL CHARACTER,IN TEXT CHARACTER )RETURNS BOOLEAN LANGUAGE JAVA
EXTERNAL NAME "com.ibm.broker.IAM3.Log4jNode.log";
------------------------------------------------------------------------------------------------------------------------
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
-- CALL CopyMessageHeaders();
DECLARE rc BOOLEAN;
CALL CopyEntireMessage();
CALL initLog4j('E:\brokerlog1.txt') INTO rc;
CALL log4j('MyFlow', 'WARN','Message from ESQL') INTO rc;
CALL log4j('MyFlow2', 'ERROR','Message2 from ESQL') INTO rc;
CALL log4j_1_1('MyFlow', 'File1', 'WARN','Message from ESQL') INTO rc;
RETURN TRUE;
END; |
I do not see the log file getting generated. What could have been wrong. Please let me know.
Thanks,
Konijeti Balaji.
[/i] |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Nov 01, 2012 6:31 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Many many many things could be wrong.
The first thing that is wrong is that you have not explained what steps you have taken to actually troubleshoot this yourself, other than throw your hands up in the air and then write a post here asking for help.
Second off, you don't need to use the node to use log4j. You can just do the same "create function" to point to real log4j classes in a log4j jar file, and included that in your bar file.
Third, you shouldn't use log4j. You should at a bare minimum use modern Java logging classes provided with the JVM, rather than log4j.
Fourth, and most importantly, you should use functions of the built in product to meet your needs rather than trying to hack in some kind of logging function. Use Monitoring and Accounting and Statistics or at least a FileOutput node.
Throw out your idea of using log4j. Start from scratch. Revisit the requirements. Revisit the product and how it works. Decide how to do this correctly. |
|
Back to top |
|
 |
Vitor |
Posted: Thu Nov 01, 2012 6:38 am Post subject: Re: Using LOG4J API in ESQL |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
balaji83it wrote: |
What could have been wrong. |
Almost anything. At a basic level, your code is not checking the rc boolean in any of the calls. Have you applied the same assumption that the call must be working to your configuration of the IAM3 support pac, i.e. that you can't possibly have made a mistake following the insturctions so it must be a fault with the pac?
Or have you actually verified the pac is installed correctly? Verified that you have all the correct configurations and access? That everything has been loaded properly?
Indeed, have you done anything apart from post here and fold your arms? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
zpat |
Posted: Thu Nov 01, 2012 7:25 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
mqjeff wrote: |
Third, you shouldn't use log4j. You should at a bare minimum use modern Java logging classes provided with the JVM, rather than log4j.
|
Jeff - I have a lot of developers using Log4J to log application errors in compute nodes (and in JCNs).
Can you please elaborate on why they shouldn't use it, and what these modern Java logging classes are (and how to use them)?
I would quite like to get rid of Log4J in our environment. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Nov 01, 2012 7:33 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
zpat wrote: |
mqjeff wrote: |
Third, you shouldn't use log4j. You should at a bare minimum use modern Java logging classes provided with the JVM, rather than log4j.
|
Jeff - I have a lot of developers using Log4J to log application errors in compute nodes (and in JCNs).
Can you please elaborate on why they shouldn't use it, and what these modern Java logging classes are (and how to use them)?
I would quite like to get rid of Log4J in our environment. |
From the old days: http://docs.oracle.com/javase/1.4.2/docs/guide/util/logging/overview.html
and in JDK 7 : http://docs.oracle.com/javase/7/docs/technotes/guides/logging/overview.html
You should otherwise really just get out of the habit of logging to files.
Some *basic* work with syslog configuration tools and syslog management will allow your app to use ESQL LOG statement instead of calling out to java.
Some *basic* work will allow you to dump out application level log messages to a queue where they can be dealt with in a more sophisticated manner rather than being written to a file.
Using broker capabilities to Monitor your flows, applications and services will allow you to configure the level of "logging" you need at an administrative level and provide you with the ability to add and remove logging on the fly without redeploy or restart or etc.
If you're writing lots of Java code, then it makes sense to think about using Java logging functions - but java.util.logging should be used instead of log4j.
But, again, Broker applications should use Broker methods and tools to perform the necessary functions to meet requirements for application logging. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Nov 01, 2012 9:01 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
As a basic example -
suppose you create a Monitoring profile that says that it will create events for every Compute.out4 terminal that gets called. Then in any ESQL that happens to need to log something, you do
Code: |
Propagate to terminal 'Out4' finalize none delete none; |
And then don't bother to connect anything to the Out4 terminal of your compute nodes.
Nominate some place in Environment or LocalEnvironment to hold the data that needs to be logged, and add that to the monitoring event configuration.
Then create a message flow that consumes the events and does what you want with them. |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Nov 02, 2012 2:52 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
mqjeff wrote: |
Nominate some place in Environment or LocalEnvironment to hold the data that needs to be logged, and add that to the monitoring event configuration.
|
Make sure you attach a parser first.
For instance with a restful service @ V7.0.0.3
the url is ......?a=b&c=d.... Well, in the event message, the & is not escaped rendering an invalid XML. Had to read it as blob, escape the & . Only then could I treat it as XMLNSC....  _________________ MQ & Broker admin |
|
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
|
|
|
|