Our modeling tools, including MagicDraw, use the Log4j logger. The configuration file is <program installation directory>/data/log4j2.xml.
The <program installation directory>/data/log4j2-test.xml file 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.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration 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>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration> |
The example below displays how information can be logged to the configured log file:
//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 https://logging.apache.org/log4j/2.x/.