web stats
[3.0] Logger templating - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 01-22-2014, 03:34 AM
lionelroux lionelroux is offline
OBX.2 Kenobi
 
Join Date: Apr 2013
Posts: 82
lionelroux is on a distinguished road
Default [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
Reply With Quote
  #2  
Old 01-22-2014, 04:04 AM
rodrosa rodrosa is offline
OBX.2 Kenobi
 
Join Date: Jul 2013
Posts: 79
rodrosa is on a distinguished road
Default

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 at 04:07 AM.
Reply With Quote
  #3  
Old 01-22-2014, 07:54 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,111
narupley is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 01-23-2014, 12:16 AM
lionelroux lionelroux is offline
OBX.2 Kenobi
 
Join Date: Apr 2013
Posts: 82
lionelroux is on a distinguished road
Default

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
Reply With Quote
  #5  
Old 01-23-2014, 07:48 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,111
narupley is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 04-16-2014, 04:46 AM
lionelroux lionelroux is offline
OBX.2 Kenobi
 
Join Date: Apr 2013
Posts: 82
lionelroux is on a distinguished road
Default

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
Reply With Quote
  #7  
Old 04-16-2014, 06:48 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,111
narupley is on a distinguished road
Default

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.
Reply With Quote
  #8  
Old 04-16-2014, 12:04 PM
lionelroux lionelroux is offline
OBX.2 Kenobi
 
Join Date: Apr 2013
Posts: 82
lionelroux is on a distinguished road
Default

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" ?
Reply With Quote
  #9  
Old 04-16-2014, 12:40 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,111
narupley is on a distinguished road
Default

Quote:
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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 11:05 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation