Announcement

Collapse
No announcement yet.

[3.0] Logger templating

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [3.0] Logger templating

    Hello,

    I've an issue in my logging file.

    All lines are like the following one :

    [2014-01-22 13:30:03,270] DEBUG (db-connector:?): MessageEvent is A04

    the connector name is not templated. It is the same thing with tranformers, processors, ...

    Is there a setting to use to fix this ?

    thks

    Lionel

  • #2
    you can get the channelName to create your own template, like:

    Code:
    var channelName = Packages.com.mirth.connect.server.controllers.ChannelController.getInstance().getDeployedChannelById(channelId).getName();
    
    logger.error(channelName +"Your Message!");
    Although, if exists another way to do that i'd like to know too
    Last edited by rodrosa; 01-22-2014, 04:07 AM.

    Comment


    • #3
      The category is something we set specifically for each JavaScript context (like "db-connector", "transformer", etc.). You can always create your own Logger object and give it your own custom category.

      The "?" refers to the line number where the logger call was made. Since you're doing manual logger.debug calls within a Rhino JavaScript context, log4j doesn't have that information and just prints out "?" instead. If the logger statement came from a Java class it would show the line number.
      Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

      Nicholas Rupley
      Work: 949-237-6069
      Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


      - How do I foo?
      - You just bar.

      Comment


      • #4
        Ok that's clear now.

        So in the log statement, it is not possible to have automatically (and by default without tuning log4J conf) the transformer (or db-connector, etc) name, step and channel name templated ?

        I mean something like that :

        [2014-01-22 13:30:03,270] DEBUG (My Channel - db-connector - step 1): MessageEvent is A04

        or at least some of these elements.
        That's a bit confusing since all log statements are written in the same log file and console. It doesn't allow us to filter by channel for instance.

        Thanks

        Comment


        • #5
          Yes, there is still a way. I've whipped up a quick code template to handle that: http://www.mirthcorp.com/community/f...7041#post37041

          If you want to include other custom metadata like the channel name, that's definitely possible as well by tweaking the code a bit.
          Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

          Nicholas Rupley
          Work: 949-237-6069
          Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


          - How do I foo?
          - You just bar.

          Comment


          • #6
            hello Nick,
            finally I found some time to implement your solution in my channel.

            As a fisrt step I just put the Channel name as the logger name; I've to say that's really more readeable when you have lots of channels deployed.

            I tweaked your code template and put the following :

            function overwriteCategories() {
            logger = org.apache.log4j.Logger.getLogger({
            'transformer': ChannelUtil.getDeployedChannelName(channelId)+'-transformer',
            'preprocessor': ChannelUtil.getDeployedChannelName(channelId)+'-preprocessor',
            'postprocessor': ChannelUtil.getDeployedChannelName(channelId)+'-postprocessor',
            'deploy': ChannelUtil.getDeployedChannelName(channelId)+'-deploy',
            'shutdown': ChannelUtil.getDeployedChannelName(channelId)+'-shutdown',
            'filter': ChannelUtil.getDeployedChannelName(channelId)+'-filter',
            'db-connector': ChannelUtil.getDeployedChannelName(channelId)+'-db-connector',
            'js-connector': ChannelUtil.getDeployedChannelName(channelId)+'-js-connector',
            'attachment': ChannelUtil.getDeployedChannelName(channelId)+'-attachment',
            'batch': ChannelUtil.getDeployedChannelName(channelId)+'-batch',
            'response': ChannelUtil.getDeployedChannelName(channelId)+'-response'
            }[logger.getName()]);
            logger.setLevel(org.apache.log4j.Level.DEBUG);
            }

            It does the job very well.

            Now I would like to add some of my custom meta-data I get while reading incomming message in the transformers steps, the ones I display in the dashboard (just as ID, connector, status, ....)

            Do you know if theses are accessible using one of the utils classes ? Which one ?

            Thanks a lot

            Comment


            • #7
              In a transformer you have access to connectorMessage, which is an ImmutableConnectorMessage object. You can get pretty much everything you need from there. Though, the connector name is already put into filter/transformer scopes as the variable connector. If you want to use custom metadata columns, realize that those are populated using the variable maps (connector map, channel map, etc.). So you can just grab that data from one of those maps, assuming you've already mapped it. By default on new channels with the HL7 v2.x data type, "mirth_type" and "mirth_source" will already be available to you from the connector map.
              Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

              Nicholas Rupley
              Work: 949-237-6069
              Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


              - How do I foo?
              - You just bar.

              Comment


              • #8
                Hi Nick,

                what I exactly want to get is what we found in the connection log tab, in the column "Connector info" (eg "Destination: File Writer - My_dest_name" or "Source: Channel reader (XML -> XML)").

                Is it possible to get such a field in the logger "name" ?

                Comment


                • #9
                  Originally posted by lionelroux View Post
                  Hi Nick,

                  what I exactly want to get is what we found in the connection log tab, in the column "Connector info" (eg "Destination: File Writer - My_dest_name" or "Source: Channel reader (XML -> XML)").

                  Is it possible to get such a field in the logger "name" ?
                  Yes, but you would have to use an internal controller to get the Channel model. Look at ChannelController to see how to do that. Note though that using internal Mirth Connect classes isn't officially supported, meaning that whatever code you write isn't guaranteed to work in a newer version.
                  Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

                  Nicholas Rupley
                  Work: 949-237-6069
                  Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


                  - How do I foo?
                  - You just bar.

                  Comment

                  Working...
                  X