A message logger is a helper for logging the message traffic of a target.

Creation of a message logger

For the creation of a message logger there is a separate service, the message logger factory. The factory can be fetched via the service registry. Then the createLogger() method is called, with the calling object itself or it's logger as argument.

final IMessageLoggerFactory mlf = CServiceRegistry.getInstance()
final IMessageLogger ml = mlf.createLogger(this);

As always, make sure that the service starter of your package has a dependency on the IMessageLoggerFactory to ensure that the factory already exists.

Logging the message handling

The handled message is logged before and after processing.

A logged message looks like this:

>>> StartTarget handled in CConnectionRegistry: 0 connections Handler=--- No=1 ------>                                   2022-11-29 20:16:20.689198000 TRACE [Queue_NS-TRANSPORT-MAIN (TRANSPORT)_QID_MAIN] de.sillysky.nyssr.impl.message.handler.registry.CMessageHandlerRegistry.internalHandleMessage (202)
Envelope Request
    Sender         =
    Receiver       =
    Instance ID    = 89
    Env ID         = 89
Record ID = c696bd (StartTarget)
    SlotCount:   4
    Slot 1       TARGET_ADDRESS
    Slot 2       ID                    MAIN
    Slot 3       OBJECT      
    Slot 4       OBJECT                de.sillysky.nyssr.impl.message.sender.CMessageSender@7c071dc8
Service registered:                                                             2022-11-29 20:16:20.691526000 DEBUG [Queue_NS-TRANSPORT-MAIN (TRANSPORT)_QID_MAIN] de.sillysky.nyssr.impl.service.CServiceRegistry.registerService (475)
<<< StartTarget 1                                                                                                        2022-11-29 20:16:20.691769000 TRACE [Queue_NS-TRANSPORT-MAIN (TRANSPORT)_QID_MAIN] de.sillysky.nyssr.impl.message.handler.registry.CMessageHandlerRegistry.internalHandleMessage (242)

Logging the message before it is delivered to the message handler consists of the ">>> StartTarget handled in CConnectionRegistry" part above the first line, as well as logging the message itself (the part between the lines).

The following is the logging within the handler, which is not the task of the message logger ("Service registered...").

Finally, logging takes place after leaving the message handler ("<<< StartTarget 1").

A sequential number is logged in the first part, as well as in the last part. This number is used to make it easier to find the two parts in the LOG itself.

Methods for logging the individual parts

This method logs the first line:

@NotNull String logBefore(@Nullable Object aOwner,
                          @NotNull String aHandlerName,
                          @NotNull CEnvelope aEnvelope,
                          @NotNull CRecord aRecord);

Logging of the message is done by the following method:

@NotNull String logMessage(@NotNull CEnvelope aEnvelope,
                           @NotNull CRecord aRecord);

This logs the last line. The method contains an argument aHandled, which is a flag whether the message was handled at all.

@NotNull String logAfter(@NotNull CEnvelope aEnvelope,
                         @NotNull CRecord aRecord,
                         boolean aHandled);

Support methods

This method is also used to log the first line. In particular, it takes into account whether the message is a request or a response.

public String logMessageHeader(@NotNull final CEnvelope aEnvelope,
                               @NotNull final CRecord aRecord);

Finally, there is a warning if the message has not been handled. The following method is responsible for that.

public String logNotHandled(@Nullable final Object aOwner,
                            @NotNull final CEnvelope aEnvelope,
                            @NotNull final CRecord aRecord);

A helper method checks if the TRACE level is enabled for the logger. Only in the TRACE level is there any output at all.

public boolean isTraceEnabled();

This method fetches a meaningful name for the record ID from the name database, if a name has been stored for it.

public String getRecordIdName(@NotNull final CRecord aRecord);


Logging of messages in a target must first be enabled in the target. The TRACE level must also be enabled for the target's logger. - Innovative Distributed System