web stats
Per Channel Log Files In Mirth Channels - Mirth Community

Go Back   Mirth Community > Mirth Connect > Development

Thread Tools Display Modes
Old 02-16-2016, 08:49 PM
skumar10 skumar10 is offline
What's HL7?
Join Date: Sep 2009
Posts: 5
skumar10 is on a distinguished road
Default Per Channel Log Files In Mirth Channels

It is often useful to have a set of logs file per channel and to also log the name of the channel for every message logged. Not only does this make debugging easier it makes it easy to track production issues proactively. You can do this with log4j appenders using the log4j.properties configuration file as follows: (windows OS)

Lets say you want to add a log file to track DEBUG LEVEL message for a specific channel.

1. open C:\Program Files\Mirth Connect\conf\log4j.properties

2. Add the following just after the 'log4j.appender.fout.layout.ConversionPattern:' setting in your default log4j file (you can tune the appender properties to your liking)

dir.logs = C:\\Mirth Connect\\logs #this is already present in default log4j.properties file.

log4j.logger.myLogger=DEBUG, mylogger
log4j.appender.mylogger=org.apache.log4j.RollingFi leAppender
log4j.appender.mylogger.layout=org.apache.log4j.Pa tternLayout
log4j.appender.mylogger.layout.ConversionPattern=% d{yyyy-MM-dd HH:mm:ss} %c : %m%n

3. In your channel log to this file as :

var channelName = Packages.com.mirth.connect.server.controllers.Chan nelController.getInstance().getDeployedChannelById (channelId).getName();

logger.getLogger("myLogger").error(channelName + "CustomMessage");

4. Deploy your channel after changes in #3. Stop and start Mirth service so log4j.properties take effect. start the channel with the logging code in #3

5. You should see the new log file appear in :

C:\Mirth Connect\logs\seconf_file.log
Reply With Quote
Old 01-04-2017, 03:31 AM
mpagnoni mpagnoni is offline
What's HL7?
Join Date: Oct 2016
Posts: 5
mpagnoni is on a distinguished road

nice hint!
I'd like just to suggest to put also a false clause to your logger addictivity clause, unless you want all the logs to go also to the standard mirth log file

log4j.additivity.myLogger = false

And, of, course, if you don't care of repeating channel name in the log file, you can simply write in any javascript transformer

var myLog=logger.getLogger("myLogger");

Reply With Quote
Old 01-04-2017, 07:39 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
Join Date: Oct 2010
Posts: 7,125
narupley is on a distinguished road

This may also be useful to you: http://www.mirthcorp.com/community/f...7041#post37041
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
Old 02-12-2017, 01:24 AM
odo odo is offline
OBX.3 Kenobi
Join Date: Feb 2017
Location: Luxembourg
Posts: 149
odo is on a distinguished road

You also might want to have a look at this thread which adds per-channel logging on the fly without having to change log4j configuration for each channel.
Reply With Quote

log4j, per channel logs

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 04:12 AM.

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