13.4.1 Define the Syntax of Log Messages

Specify the details that you want to record in the logs and the syntax of the log messages.

To view the logs emitted by MicroTx in a Kubernetes cluster, you can set up the Elasticsearch, Fluentd or Fluent bit, and Kibana (EFK), Elasticsearch, LogStash, and Kibana (ELK) stack, or any other application to aggregate and view the log files of MicroTx coordinator and applications at a single place. For information about setting up EFK or ELK stack, refer to the application's product documentation.
After setting up the EFK or ELK stack, you must perform the following steps once to specify the details that you want to record in the logs and the syntax of the log messages.
  1. Define the parser filters for the log aggregator. The following example defines the parsers for Fluentbit. The Regex field provides the syntax of the log message and the details that are logged. Similarly, you can define the parsers for any log aggregator that you want to use. Refer to the log aggregator's product documentation for more details.
        [PARSER]
            Name  mtxnodejslib
            Format regex
            Regex  ^(?<timestamp>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)\s+::\s+(?<transactionId>[a-f0-9-]+)\s+-\s+(?<message>.+)$
            Time_Key timestamp
            Time_Format %Y-%m-%dT%H:%M:%S.%zZ
         
        [PARSER]
            Name  mtxlraspringbootlib
            Format regex
            Regex  ^(?<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\s+(?<log_level>\w+)\s+(?<numeric_value>\d+)\s+---\s+\[(?<thread_info>[\w-]+)\]\s+(?<logger_name>\S+)\s+:\s+(?<transactionId>\S+)\s+-\s+(?<message>.+)$
            Time_Key timestamp
            Time_Format %Y-%m-%d %H:%M:%S.%z
     
        [PARSER]
            Name  mtxhelidon
            Format regex
            Regex  ^(?<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\s+(?<log_level>\w+)\s+---\s+\[(?<thread_name>[^\]]+)\]\s+(?<logger_name>[^:]+)\s+:\s+(?<transactionId>[a-f0-9-]+)\s+:\s+(?<log_message>.+)$
            Time_Key timestamp
            Time_Format %Y-%m-%d %H:%M:%S.%z
     
        [PARSER]
            Name  mtxxaspringbootlib
            Format regex
            Regex  ^(?<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\s+(?<log_level>\w+)\s+\d+\s+---\s+\[(?<thread_name>[^\]]+)\]\s+(?<logger_name>[^:]+)\s+:\s+(?<transactionId>[a-f0-9-]+)\s+:\s+(?<log_message>.+)$
            Time_Key timestamp
            Time_Format %Y-%m-%d %H:%M:%S.%z
    To view the example logs that correspond to the syntax you have specified in the parser, see Sample Log Messages.
  2. For the MicroTx Java library, add the MDC key microtx-txnId in log4j.PatternLayout to specify the syntax of the log messages.

    The following code sample demonstrates how to create the MDC context microtx-txnId and specify the position of the various fields in the log message. In this example configuration for Log4J, the name of the logger is oracle.tmm, the log level is set to DEBUG, and provide the AppenderRef as MicroTxLib. The PatternLayout specifies the syntax of the log messages. The %X{microtx-txnId} refers to the unique transaction ID. When MicroTx logs a message, %X{microtx-txnId} is replaced with the actual transaction ID.

    <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="WARN">
        <Appenders>
            <Console name="Console" target="SYSTEM_OUT">
                <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}  %-5level --- [%t] %-50.70C : %X{microtx-txnId} : %msg%n%throwable"/>
            </Console>
     
            <Console name="MicroTxLib" target="SYSTEM_OUT">
                <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}  %-5level --- [%t] %-50.70C : %X{microtx-txnId} : %msg%n%throwable"/>
            </Console>
        </Appenders>
        <Loggers>
            <Logger name="oracle.tmm" level="DEBUG" additivity="false">
                <AppenderRef ref="MicroTxLib"/>
            </Logger>
            <Root level="info">
                <AppenderRef ref="Console"/>
            </Root>
        </Loggers>
    </Configuration>

    If you want to use another tool to log the information, provide the syntax of the log message in a similar way.