Wiki Spaces


Get Help from Others

Q&A: Ask OpenMRS
Discussion: OpenMRS Talk
Real-Time: IRC Chat | Slack


Page tree
Skip to end of metadata
Go to start of metadata

Please note that the feature describe here is only available in Platform 2.4.4+, 2.5.1+ and, once it's released 2.6.0+

OpenMRS uses the Apache Log4J2 project to support logging, which comes with a very rich set of configuration options for determining how messages are logged, determining which messages go where, etc. Previously, however, this configuration has been somewhat hidden or inaccessible to administrators. With the release of the above mentioned version, the Log4J2 settings can now be fully controlled via a log4j2.xml file placed either in the OpenMRS Application Data Directory or in the configuration sub-directory of the OpenMRS Application Data Directory.

The default OpenMRS logging configuration can be found on GitHub as part of the openmrs-core project. And looks something like this (as of ):

<?xml version="1.0" encoding="UTF-8" ?>

    This Source Code Form is subject to the terms of the Mozilla Public License,
    v. 2.0. If a copy of the MPL was not distributed with this file, You can
    obtain one at OpenMRS is also distributed under
    the terms of the Healthcare Disclaimer located at

    Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
    graphic logo is a trademark of OpenMRS Inc.


<Configuration xmlns="">
		<!-- The default pattern is stored as a property so that it's only defined once.
		     It's also quite challenging to escape using Log4j2's variable substitution. -->
		<Property name="defaultPattern">%p - %C{1}.%M(%L) |%d{ISO8601}| %m%n</Property>
		<!-- the console appender is not required but usually a good idea -->
		<Console name="CONSOLE" target="SYSTEM_OUT">
			<PatternLayout pattern="${openmrs:logLayout:-${defaultPattern}}" />
		<!-- OpenMRS should have an appender called "OPENMRS FILE APPENDER" that appends to a file -->
		<RollingFile name="OPENMRS FILE APPENDER"
			<PatternLayout pattern="${openmrs:logLayout:-${defaultPattern}}" />
				<OnStartupTriggeringPolicy />
				<SizeBasedTriggeringPolicy size="10 MB" />
			<DefaultRolloverStrategy max="1" />
		<!-- The MEMORY_APPENDER is used to keep a subset of logging messages in memory to be displayed to the user.
		 	 If one is not configured here, it will be created automatically. -->
		<Memory name="MEMORY_APPENDER"
				bufferSize="200"> <!-- bufferSize is how many messages are kept in memory -->
			<PatternLayout pattern="${openmrs:logLayout:-${defaultPattern}}" />
		<Logger name="org.apache" level="WARN" />
		<Logger name="org.hibernate" level="ERROR" />
		<Logger name="net.sf.ehcache" level="ERROR" />
		<Logger name="org.springframework" level="WARN" />
		<Logger name="org.openmrs" level="WARN" />
		<Logger name="liquibase" level="INFO" />
			This controls the LoggingAdvice class that wraps around the OpenMRS services 
			WARN == don't log anything special for the services
			INFO == log all setters
			DEBUG == log all setters & log all getters & log execution time
		<Logger name="org.openmrs.api" level="INFO" />
		<Logger name="org.apache.fop" level="ERROR" />
		<!-- Hide the useless MissingResourceException -->
		<Logger name="" level="ERROR" />
		<Logger name="" level="ERROR" />
		<Root level="WARN">
			<AppenderRef ref="CONSOLE" />
			<AppenderRef ref="MEMORY_APPENDER" />
			<AppenderRef ref="OPENMRS FILE APPENDER" />

Extensive details on how to configure Log4J2 can be found in the Log4J2 manual. However, there are some OpenMRS-specific points that are worth considering:

  • If you have an appender that writes to a file it should have the name OPENMRS FILE APPENDER as shown above. This will enable OpenMRS to tell you where your log file actually is.
  • The MEMORY_APPENDER is used to hold logging messages in memory for display, e.g. in the View System Logs link. You are not required to have this in your configuration, but if you do not, a memory appender with the default settings (100 entries using the pattern %p - %C{1}.%M(%L) |%d{ISO8601}| %m%n) will be automatically created and attached to the root logger for you.

In addition, as can be seen in the above file, OpenMRS exposes some OpenMRS-specific logging configuration settings, specifically:

  • openmrs:logLayout: this will be the value of the log.layout setting. If you want that setting to be able to control the log layout, you should use it in your appenders as shown above.
  • openmrs:logLocation: this will be the value of the log.location  setting. If you want that setting to be able to control where the log file is output, you should use it as shown above.
  • openmrs:applicationDirectory: this will be the location of the OpenMRS Application Data Directory. It is useful for ensuring your logs are written there, if that is the desired behaviour.

NB If you do not use openmrs:logLayout  and openmrs:logLocation in your log4j2 configuration file, then the log.layout and log.location  settings will have no effect.

  • No labels