Replies: 1 comment 1 reply
-
**Ignore this my idea was wrong. I was looking only at StringWriter and the map and ignoring that the writer has to exist for the log appender to work. ** I wonder if you're leaking memory because the connector map is going to keep that writer on live heap because its never closed by calling toString. Instantiating a writer shouldn't be expensive. Instead of storing the writer object in memory try this:
If you do this does your memory leak go away or not? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My problem: I want easy debugging and follow a single message's log in the Mirth GUI. But Mirth logs contain lots of mixed up entries from different channels and messages and the GUI can only show the last 99 entries. All this makes debugging tough.
My idea: Collect the logs of one message programmatically and make it available in Dashboard's "Mapping" tab using a
channelMap
variable.My solution:
WriterAppender
made of aStringWriter
StringWriter
inchannelMap
In poetic words what's happening (code snippets below):
custom_logger()
for the first time creates a logger named<channelName>[:<messageId> (if exists)]:<originalName>
, example:MyChannel:324:preprocessor
where324
is the message IDcustom_logger()
invokes the call ofadd_logger_appender()
add_logger_appender()
creates aStringWriter
, stores it inchannelMap("__LOG__")
, creates aWriterAppender
and appends it to the current loggerchannelMap("__LOG__")
contains a copy of the loggerMyChannel:324:preprocessor
custom_logger
is called, a new loggerMyChannel:324:transformer
is createdadd_logger_appender
this time, the keychannelMap ("__LOG__")
already exists and the storedStringWriter
living there is used to create a newWriterAppender
that is appended to the current loggerchannelMap("__LOG__")
now contains a copy of both loggers,MyChannel:324:preprocessor
andMyChannel:324:transformer
channelMap("__LOG__")
contains a copy of all loggers that belong to the same message (as thechannelMap
variable exists separately in the scope of each single message)Problem with my solution: after some days I'm getting
java.lang.OutOfMemoryError: Java heap space
errors and Mirth crashesQuestion 1: Do you have any idea why memory is running full? I was expecting that Java's garbage collector is cleaning up loggers, their appenders and
channelMap
variables including references to theStringWriter
sQuestion 2: If - for any reason - it is "as is" and I need to clean up on my own, what's the best solution?
Error details (investigation of heap dump):
Digging little bit deeper into the dump reveals that the Hashtable entries are not cleaned up properly. All of them contain
java.io.StringWriter
s of theorg.apache.log4j.Logger
.Code snippets:
Code Template Library
custom_logger()
:Code Template Library
add_logger_appender()
:Channel transformer:
Beta Was this translation helpful? Give feedback.
All reactions