Discussion:
Logging to different files , different messages using Log4j properties
(too old to reply)
b***@gmail.com
2018-04-09 14:41:01 UTC
Permalink
Raw Message
Hi ,

I am having trouble logging to my custom log and ibmdi.log two different messages. Currently its printing same messages to both logs and am using File Appender. Any help would be much appreciated?

Plus am new to TDI , just getting to know it.

Thanks in Advance,
Noah B
2018-04-09 15:20:49 UTC
Permalink
Raw Message
Post by b***@gmail.com
Hi ,
I am having trouble logging to my custom log and ibmdi.log two different messages. Currently its printing same messages to both logs and am using File Appender. Any help would be much appreciated?
Plus am new to TDI , just getting to know it.
Thanks in Advance,
Noah B
2018-04-09 18:50:25 UTC
Permalink
Raw Message
Post by b***@gmail.com
Hi ,
I am having trouble logging to my custom log and ibmdi.log two different messages. Currently its printing same messages to both logs and am using File Appender. Any help would be much appreciated?
Plus am new to TDI , just getting to know it.
Thanks in Advance,
And Also Am trying to use the log4j property to set different levels to both the logs...
Franzw
2018-04-10 09:34:26 UTC
Permalink
Raw Message
Post by Noah B
Post by b***@gmail.com
Hi ,
I am having trouble logging to my custom log and ibmdi.log two different messages. Currently its printing same messages to both logs and am using File Appender. Any help would be much appreciated?
Plus am new to TDI , just getting to know it.
Thanks in Advance,
And Also Am trying to use the log4j property to set different levels to both the logs...
Now - if you expect help from a community it is normally a good idea accurately to show what you have done...

This site gives a good advice on how to ask questions : http://www.catb.org/esr/faqs/smart-questions.html

HTH
Regards
Franz Wolfhagen
Noah B
2018-04-10 15:29:44 UTC
Permalink
Raw Message
Post by b***@gmail.com
Hi ,
I am having trouble logging to my custom log and ibmdi.log two different messages. Currently its printing same messages to both logs and am using File Appender. Any help would be much appreciated?
Plus am new to TDI , just getting to know it.
Thanks in Advance,
Thanks for the tips Franz, unfortuantely the site doesn't work. I am trying to get myLogger from LogConnector and set the level and accordingly log it to my custom log. Here is what I have tried but I couldnt get it.

L=LogConnector.connector.getLogger();
H=L.myLogger;
B=H.setLevel(ERROR);

//SomeLogger=com.ibm.di.log.TDILog4j( org.apache.log4j.Logger);
task.logmsg(B);


Thanks,
Eddie Hartman
2018-04-10 18:15:57 UTC
Permalink
Raw Message
You don't need a Connector to do logging, just use task.logmsg(). You set up appenders for an AL under Options... Log Settings. Or am I misunderstanding ur post..?

-Eddie
TDI Launchpad: https://ibm.biz/BdjiM6
Noah B
2018-04-10 20:49:46 UTC
Permalink
Raw Message
Post by b***@gmail.com
Hi ,
I am having trouble logging to my custom log and ibmdi.log two different messages. Currently its printing same messages to both logs and am using File Appender. Any help would be much appreciated?
Plus am new to TDI , just getting to know it.
Thanks in Advance,
Thanks for your Reply Eddie Hartman. I am a fan and great admirer of your blogs they really helped me a lot when i began starting TDI.

What I am trying to do is that I want to set my levels using script from TDI by importing the log4j properties and use the LogConnector File Logger to print the messages to my custom Log. If I just use task.logmsg() it will print same to both ibmdi.log and custom log.

My goal is to have different messages to user by implementing some properties from the log4j class.

Thanks,
j***@gmail.com
2018-04-11 03:21:01 UTC
Permalink
Raw Message
Hi Noah,

I am guessing you have an AssemblyLine with a connector named LogConnector in Passive state. The default for the LogConnector is to log messages of all levels.

If you want to change the log level for this connector, it must be done before
the connector is initialized. There is no configuration option to do this,
but you can add code like this in the "Before Initialization" hook for the connector:

thisConnector.setConnectorParam("com.ibm.di.log.level", "ERROR")


After the connector have been initialized, you can then log messages like this,
assuming the connector has been set up to map all attributes:

e = system.newEntry();

e.message="Hello1"
e.level="DEBUG"
LogConnector.add(e) // Will not be logged if the connector is only logging messages of ERROR or higher level

e.message="Hello2"
e.level="ERROR"
LogConnector.add(e) // Will be logged if the connector is logging ERROR messages
Noah B
2018-04-11 14:51:06 UTC
Permalink
Raw Message
Post by b***@gmail.com
Hi ,
I am having trouble logging to my custom log and ibmdi.log two different messages. Currently its printing same messages to both logs and am using File Appender. Any help would be much appreciated?
Plus am new to TDI , just getting to know it.
Thanks in Advance,
Hey jens...,

Thanks for your reply. Good thing to know it from different perspective. Here is my code what I have done and tell me if I can do it in a better way .

Am getting my levels from the properties file dynamically as the user may change it as per their need and also using some methods from the log4j class. I have associated a custom log to my LogConnector and it prints messages here to that. And other messages default to ibmdi.log.

what do you think of my code?

Thanks,


Cat = main.getMetamergeConfig().getExternalProperties().getStringParameter("Category");

//LogConnector.logmsg(Cat );
Lev=org.apache.log4j.Level;
L=LogConnector.connector.getLogger();
H=L.myLogger;

H.setLevel(Lev.toLevel(Cat));

J=H.getLevel();

H.info("Log level was set to: " + Lev.toLevel(Cat));
H.warn("Log level was set to: " + Lev.toLevel(Cat));
H.error("Log level was set to: " + Lev.toLevel(Cat));
H.fatal("Log level was set to: " + Lev.toLevel(Cat));

Loading...