One Star

Logging to xml file

Hi
I have two questions about tLogCatcher and tAdvancedOutputFileXML. I'm using TOS 3.1 in a java project.
1)
I'm trying to write into a xml file the logs from a tLogCatcher outputs.
The test job consist in three tWarn, a tLogCatcher plugged to a tReplicate which outputs the logs to a tLogRow, a tFileOutputDelimited and finally to a tAdvancedFileOutputXML.
At the standard output and the csv output i get all of the logs messages but only the last log row is written in the xml output file although a loop element is defined.
See the attached screeenshots
I also tried to set the "append the source xml file" option but this result in a NullPointerException:
java.lang.NullPointerException
at tdsconfiggen.test_0_1.test.tLogCatcher_1Process(test.java:2851)
at tdsconfiggen.test_0_1.test.tWarn_1Process(test.java:260)
at tdsconfiggen.test_0_1.test.runJobInTOS(test.java:3072)
at tdsconfiggen.test_0_1.test.main(test.java:2989)
The corresponding instruction is:
// build loop xml tree
org.dom4j.Element loop_tAFOX_1 = subTreeRootParent_tAFOX_1
.addElement("log");
Does someone already met these ?
2)
Is there any way to force the tLogCatcher subjob to start after another component ?
Concretely i would like to set the xml output logfile path with a context variable initialized after the job has started (with a tContextLoad)

Thanks
Jonathan
5 REPLIES
Community Manager

Re: Logging to xml file

Hello guy
I also tried to set the "append the source xml file" option but this result in a NullPointerException:
java.lang.NullPointerException

Using 'append source xml file' feature, you must set a group element.
2)
Is there any way to force the tLogCatcher subjob to start after another component ?

Yes, just like
tFileInputDelimited---tConextLoad
|
onsubjobok
|
tWarn_1
|
onsubjobok
|
tWarn_2
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Logging to xml file

Hi Shong
1)
Yeah that solved it, thanks !
2)
I can effectively log my messages using tWarn at determined moment of the job, my problem is to control when the output file behind the tLogCatcher is created and its filepath determined.
My goal is to load context parameters from a file and after this, some other parameters are loaded also from a file and are used to make string substitutions which modify the previously loaded context parameters.
This works well, using context.getProperty / context.setProperty, my context is well updated.
But in facts, the logfile filepath used is the initial one which was set in the default context, so I think the tLogCatcher subjob always starts first and then the path of the logfile is set at this moment, I already tried to plug the onsubjobok trigger to the tLogCatcher and also tried to use the tPrejob component but without result.
I'll verify this behavior again

Best regards
Jonathan
One Star

Re: Logging to xml file

Hi all,
I can confirm that the tLogCatcher part of the job always start first.
In my case, this causes the xml logfile path to be wrong because it does not reflect the value loaded by the tContextLoad (and whatever append after the tContextLoad, here a substition of a part of this value)
---
I found another strange thing, when specifying just a filename as value of the tAdvancedFileOutputXML (e.g. "test.log.xml"), an exception:
Exception in component tAdvancedFileOutputXML_2
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
This correspond to the following part of code:
if (fileName_tAFOX_2.substring(
fileName_tAFOX_2.lastIndexOf("/")).lastIndexOf(".") > 0) {
file_tAFOX_2 = fileName_tAFOX_2.substring(0,
fileName_tAFOX_2.lastIndexOf("."));
} else {
file_tAFOX_2 = fileName_tAFOX_2;
}
java.io.File createFiletAFOX_2 = new java.io.File(
fileName_tAFOX_2);
This is due to lastIndexOf("/") call inside the substring call (not very nice !)
I think having such a filename is a valid use case so this may be a bug ...
Community Manager

Re: Logging to xml file

Hello
I think having such a filename is a valid use case so this may be a bug ...

Here you must specify one file path, not file name. There is a button for browsing a file path, so there is alway one '/' at least in the file path.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Logging to xml file

Hi Shong,
You're right, this must be the way to do and if the need is to put the file in the current execution directory this may be done by adding a "./" prefix to the file path.
Concerning the start time of tLogCatcher chain, do you know any way to control this ?
Best regards