4 Replies Latest reply on May 12, 2015 2:18 AM by Abhijit Humbe

    How log in BPM Script Task?

    Nabeel Ahmed Newbie

      HI Everyone!

       

      I have create a bpmn2 process, and have some script task in it.

      Now I want to add some logging there.

       

      How can have logger there? so that I can use it.

       

      regards,

      Nabeel

        • 1. Re: How log in BPM Script Task?
          Patrick Schäfer Newbie

          If you want to output text to the console you can simply use

          System.out.println("Hello World");

          in your script task if you use Java as language. Depending on your server configuartion, the server will print this also to its server log.

          • 2. Re: How log in BPM Script Task?
            Abhijit Humbe Master

            Hi,

            You can use slf4j/log4j API's in script task to capture logging as well. Foe this you have to declare project dependency on log4j.jar/slf4j.jar, like as:

             

            ~~~~

            <dependency>

            <groupId>log4j</groupId>

            <artifactId>log4j</artifactId>

            <version>1.2.15</version>

            </dependency>

            ~~~~

             

            Or you can upload log4j/slf4j jar into server repository and then specify project dependency on log4j.jar/slf4j.jar file.To upload log4j/slf4j jar into repository go to "Authoring-->Artifact repository-->upload"(specify groupid,artifactid & version if required).Then go to "Authoring"-->Project authoring-->Tools-->Project Editor-->Dependencies-->Add from Repository. Import 'org.apache.log4j.logger' in BPMN process and configure logging as per your requirement.

            Hope it helps..

            • 3. Re: How log in BPM Script Task?
              Nabeel Ahmed Newbie

              @Patrick i was already using the system.out.println(); that is working, but now want them to replace with some logging api. Either Log4j or jboss-logging.

               

              @Abhijit you got my point, I don't have any issue with configuring the api. The confusion is how can i get the logger in script task. In script i cannot pass the class to logger.getLogger( class ) method because there is no class in my script.

              Should i pass any string to get the logger using getLogger(String text) method?

               

              I hope you understand my question.

              • 4. Re: How log in BPM Script Task?
                Abhijit Humbe Master

                Hi,

                Yes, we have to use 'getLogger(String)' method. like as:

                ~~~~

                Logger logger = null;

                logger = Logger.getLogger("Logger");

                logger.info("Process Name:-"+kcontext.getProcessInstance().getProcessName());

                logger.info("Node Name:-"+kcontext.getNodeInstance().getNodeName())

                ~~~~

                It will capture logging like as:

                =============

                11:26:33,995 INFO  [Logger] (http-localhost.localdomain/127.0.0.1:8080-2) Process Name:-DemoProcess

                11:26:33,995 INFO  [Logger] (http-localhost.localdomain/127.0.0.1:8080-2) Node Name:-Script Task

                11:26:33,995 INFO  [Logger] (http-localhost.localdomain/127.0.0.1:8080-2) Process InstanceID=8

                =============

                So its really difficult to track logging when we you have multiple process instances running with multiple script tasks. So I will suggest to create logger object like as:

                ~~~~

                Logger logger = null;

                logger = Logger.getLogger(kcontext.getProcessInstance().getProcessName()+"|"+kcontext.getNodeInstance().getNodeName()+"|"+kcontext.getProcessInstance().getId());

                ~~~~

                It will capture logging like as:

                =============

                11:32:46,174 INFO  [DemoProcess|Script Task|10] (http-localhost.localdomain/127.0.0.1:8080-1) Process Name:-DemoProcess

                . .

                =============

                With this logging you can easily check processName,NodeName and ProcessInstanceId.

                 

                Hope it helps..