Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
rmartin2
Creator II
Creator II

Problem with redirecting output

Hello,

I'm facing an issue on putting my logs into a file. The issue is with Talend ESB, but this is a pure DI matter. ESB doesn't change anything except the number of hair I lost at this.
Context info :
[list=*]
  • Talend TOS 6.1.1

  • Windows/RHEL OS

  • Here is my job template :
    WS_Request ==> Consumer_1==>Consumer_2==>WS_Response

    Each of them have a prejob followed by a tJava :

    String logFile = routines.context.getLogFilePath(hostname,"MY_JOB_NAME");

    System.setOut(new java.io.PrintStream(new java.io.FileOutputStream(logFile,true)));
    System.setErr(new java.io.PrintStream(new java.io.FileOutputStream(logFile,true)));


    The problem was not easy to understand at first, but I realized that System.out is a static object ... :
    [list=*]
  • When Master Job starts, it creates a file, write some things into it and call the first consumer.

  • This consumer then changes the System.out, which break the log file for the master

  • Same thing happen for Consumer 2 which take over the System.out, and keep it for him

  • in the end, only the Consumer_2 can log things 😕


  • The scenario is an easy one, because job are ordered. In reality, PreJob is launch when the .kar is deployed on the karaf container. This was the hard thing to understand, because whenever I undeploy/deploy a WS, the order keep changing randomly.

    Is there any way possible to have the console output redirected to a file, depending on jobName, and not overlapping each other.
    I can't use custom component (I'm thinking about tJobInstance packages), because Webservice exports to kar/jar is broken when a component uses a library that karaf uses (like log4j).

    Any help would be appreciated 0683p000009MA9p.png
    My goal here is to catch anything going through the console, coming from (actually) 5 difference jobs, maybe more in the future.
    I don't want to use a DB connection since it's a 24/7 up and running job.

    Sincerely,
    Renald.
    Labels (3)
    4 Replies
    Anonymous
    Not applicable

    Hi 
    There is a global variable called jobName that stores the current Job name, I don't know whether you have used it in the job for each job. 

    The scenario is an easy one, because job are ordered. In reality, PreJob is launch when the .kar is deployed on the karaf container. This was the hard thing to understand, because whenever I undeploy/deploy a WS, the order keep changing randomly.

    Can you please upload a screenshot of job? is it the component execution order or the console output order?
    The scenario is an easy one, because job are ordered. In reality, PreJob is launch when the .kar is deployed on the karaf container. This was the hard thing to understand, because whenever I undeploy/deploy a WS, the order keep changing randomly.

    Take a look at tRedirectOutput component, this component redirect all the console output to a file.

    Regards
    Shong
    rmartin2
    Creator II
    Creator II
    Author

    Hello shong,

    I've used jobName in my tJava to create the filename, that part works, but the problem is that System.out is unique (because it's static). So if you declare another file, System.out will just move to this file because it's in one unique JVM.
    This is my front job structure :
    0683p000009MFbo.png



    My goal is to have 3 WS, all in "keep listening" mode :
    [list=*]
  • FRONT (the example above)

  • CONSUMER_1

  • CONSUMER_2

  • And so 3 separate log, with timestamps in milliseconds. In need to be able to say :
    [list=*]
  • This part took XX millis

  • The write of the file took X milli

  • the whole job took XX milli


  • The front job, the one in example, is in keep listening mode, which cannot be used with tStatCatcher and tLogCatcher 0683p000009MPcz.png (this stuff is pretty awesome for what I need, but I must pass sadly).


    I've looked at tRedirectOutput, and it's exactly the same code inside the component, compared to the one I typed above. Also, there's the problem of packaging the bundle with custom component, so it might not be a good idea to use one.

    My colleague worked with me on the subject (and confirmed that the building of the bundle doesn't take external libs since it conflict with native libraries). We tried to alter the custom component to completely deactivate the logging part, and the problem is still there.
    So we went on a more "hard coded" logging solution : modifying lo4j conf like that (the first answer, not the original post) :
    Is it worth it to throw some hours in that subject, considering the fact that is quite stable, but could be changed without hours of rework if I want a different separation of my files ?

    Thx in advance for your help.
    Anonymous
    Not applicable

    Hello rmartin  

    Sorry for delayed reply. I have consult with our developer and was told that this is possible with MDC logging, please refer to this article:
    http://blog.nanthrax.net/2014/08/mdc-logging-with-apache-karaf-and-camel/

    Regards
    Shong
    rmartin2
    Creator II
    Creator II
    Author

    Hello shong,

    Thank you for the link, I'll look into it to see if it's doable to put that kind of logging in place without much rework of our jobs.
    I'll tell you if I managed to use it in a simple way for other users.


    Sincerly,
    Renald.