Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Our modeling tools, including MagicDraw, use the Log4j logger. The configuration file is <program installation directory>/data/debuglog4j2.propertiesxml.

Note

The <program installation directory>/data/log4j2-test.properties xmlfile is used as a configuration file for program test cases.

The following sample presents the content of the configuration file. It configures the logger to print INFO category messages to a console with a specific pattern.

Code Block
languagetextxml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration  log4j.appender.SO=org.apache.log4j.ConsoleAppender 
    log4j.appender.SO.layout=org.apache.log4j.PatternLayout 
    log4j.appender.SO.layout.ConversionPattern=status="warn" monitorInterval="30">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d [%t] [%X{id} %X{action_name}] %-5p %c - %m%n"/>
        </Console>
    </Appenders>
    log4j.rootCategory=INFO,SO<Loggers>
        <Root level="info">
            <AppenderRef ref="Console"/>
        </Root>
    </Loggers>
</Configuration>


The example below displays how information can be logged to the configured log file:

Code Block
languagetext
//used to get logger with category name
org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger("GENERAL");
  
// set thread context values (optional)
ThreadContext.put("id", "My id");
ThreadContext.put("action_name", "My Action");
  
logger.info("Logging info");
logger.error("Logging error");
  
//by default the text will be displayed in the form of :
//0000-00-00 00:00:00,000 [THREAD] [My id My Action] INFO  GENERAL - Logging info
//0000-00-00 00:00:00,000 [THREAD] [My id My Action] ERROR GENERAL - Logging error


More information about Log4j can be found at httphttps://logging.apache.org/log4j/12.2x/.