0% found this document useful (0 votes)
17 views9 pages

Lab21 LOG4J

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views9 pages

Lab21 LOG4J

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

LOG4J

Table of Contents

Introduction: 1
What is LOG4J? 1
Levels:- 2
Drawbacks in Log4J:- 2
Trace Logs:- 3

Understanding ACE Concept: 3


EXAMPLE: 3

Testing: 8

Conclusion: 9
Introduction:

What is LOG4J?

● Log4j is used by developers to keep track of what happens in


their software applications or online services. It's basically a
huge journal of the activity of a system or application.
● This activity is called 'logging' and it's used by developers to
keep an eye out for problems for users.

Logger:- Store the logs


Appender:- It sends the data to the preferred destination.
Layouts:- It creates Formatting Style-sheets.

Levels:-

Debug:- It stores all types of information.


Info:- It stores the actual information.
Warn:- It stores the warning data.
Fatal:- It stores the Exception Data.

Drawbacks in Log4J:-

It consumes more memory.


It doesn't check levels.
it is java Dependent
In LOG4J, we can just call the java routines.
Trace Logs:-

Trace Logs store all types of information.


If we give the message tree the pattern property of the trace node.
Then it will print all the properties,headers and payloads.
It doesn't have a level which is available in Log4J.

Understanding ACE Concept:


EXAMPLE:

STEP 1:

Paste these three jar files(Log4j-1.2.8 , Log4jLoggingNode_v1.2.1 ,


Log4jLoggingNode_v1.2.1_JVM14) in a shared class.
STEP 2:

Create one folder and paste the dtd file and configuration file.
Copy the path of the dtd file and paste it in the configuration file.

STEP 3:

Some changes in configuration file


● Copy the dtd file path and paste it .
<!DOCTYPE log4j:configuration SYSTEM "C:\inlog\log4j.dtd">
● Appender name(indhu) , Appender-ref name of INFO (indhu)
should be same and logger name(indrani) of INFO should be
different.
● Logger name (indrani) is given in ESQL code.
● Here create the folder and give it in level INFO .change the slash(/).
● Then the data will be stored as info.txt format. Here giving info.txt
is the pattern to store the logs.
<param name="File"
value="C:/filelogs/info.txt" />
STEP 4:

Message Flow:

ESQL code:

Doing transformation from XMLNSC to JSON format.


Here give the path of the configuration file with single quotes.
('C:\inlog\Log4jConfigurationFile.xml')
DECLARE config EXTERNAL CHARACTER 'C:\inlog\
Log4jConfigurationFile.xml';
DECLARE var BOOLEAN;

CREATE COMPUTE MODULE File_Logging1_Compute


CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL initLog4j(config)INTO var;
CALL CopyEntireMessage();
RETURN TRUE;
END;

CREATE PROCEDURE CopyEntireMessage() BEGIN

SET OutputRoot.JSON.Data = InputRoot.XMLNSC;


DECLARE input_req, output_res CHARACTER ;

SET input_req = CAST(ASBITSTREAM(InputRoot.XMLNSC


CCSID InputRoot.Properties.CodedCharSetId ENCODING
InputRoot.Properties.Encoding)AS CHARACTER CCSID
InputRoot.Properties.CodedCharSetId);
SET output_res = CAST(ASBITSTREAM(OutputRoot.JSON.Data
CCSID InputRoot.Properties.CodedCharSetId ENCODING
InputRoot.Properties.Encoding)AS CHARACTER CCSID
InputRoot.Properties.CodedCharSetId);

CALL writeToLogFile(MessageFlowLabel, 'indrani',


'INFO','Application Data:'||input_req) INTO var;
CALL writeToLogFile(MessageFlowLabel, 'indrani',
'INFO','Application Data:'||output_res) INTO var;
END;
END MODULE;
CREATE FUNCTION writeToLogFile( 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 initLog4j( IN CONFIG_FILE_NAME


CHARACTER )
RETURNS BOOLEAN
LANGUAGE JAVA
EXTERNAL NAME "com.ibm.broker.IAM3.Log4jNode.initLog4j";

Testing:

And also check in logs (C:/filelogs/info.txt)


Conclusion:
To store the logs , using log4j.

You might also like