Berlioz Mode

What is the Berlioz mode?

The Berlioz mode is a special immutable configuration value that Berlioz uses to determine which set of configuration files it should load.

It is generally used to distinguish between types of servers that may require slightly different configurations such as production server and local development server.

For example, when on a development server, some configurations values related to the host may be different or the logging may include debug information.

Current mode

To determine what mode is currently being used by Berlioz, you can look at the Berlioz initialisation log. When the Berlioz initialisation Servlet starts, Berlioz prints on the system output the main initialisation log, including the version number and mode as well as how it was computed.

For example:

[BERLIOZ_INIT] ===============================================================
[BERLIOZ_INIT] Initialing Berlioz 0.9.20...
[BERLIOZ_INIT] Application Base: /srv/berlioz/sampleapp/WEB-INF
[BERLIOZ_INIT] Mode: derived from XML configuration file.
[BERLIOZ_INIT] Mode: 'dev'


This log can be found directly in your console at startup or in the internal log of your server (depending on where your application server send the system output).

Setting the mode

The mode is loaded when the Berlioz starts. More specifically, it is loaded by the Berlioz initialization servlet: InitServlet . This usually happens when the application or application server is restarted.

The Berlioz initialization servlet will load the first possible value from:

  1. The initialization parameter of the InitServlet
  2. The system property berlioz.mode
  3. The only config-[mode].xml that exists
  4. "default"

1. Initialization parameter

The mode can set by assigning the "mode" initialization parameter to the InitServlet in the Web descriptor (/WEB-INF/web.xml).


This method will override any other method.

2. System property

Alternatively, the mode can be set using a Java System Property .

This is usually set when the Java Virtual Machine starts using the -D command line option:

java  ... -Dberlioz.mode=[mode] ...

Typically, if your application server (such as Jetty, Tomcat, etc...) starts with a service, this can be set as one of the command line options on the service.

On Linux, this file would be in the /etc/init.d/ folder.

On Windows, this can be inserted in the .cmd or .bat file when starting java.

3. Single configuration file

If the mode wasn't set using an initialization parameter or a system property. Berlioz will try to guess the mode by looking at the config files available in the /WEB-INF/config/ folder.

If there is only one file matching "config-[mode].xml" Berlioz will assume that the mode to use the value of [mode].

If there are multiple files or no such files, Berlioz will fall back on "default".


A developer works on Windows and wants to have all debugging messages displayed on the console while developing the application. The production server is a Linux machine and only warnings should be stored as logs. Also the application is using an API key to a third party app and is the development machine is using a different API key.

The developer can create a "dev" mode and store his development API key in "config-dev.xml" and the logging configuration in "logback-dev.xml". She only leaves these mode specific files in the /WEB-INF/config and starts the application server locally relying on Berlioz to pick up the correct mode.

In production, she defines mode "production" and specifies it directly in the service file to ensure that only that mode can be used on the server. The "config-production.xml" and "logback-production" contain the appropriate configuration for the server.


What modes to use

There is no restriction the name, but by convention "dev" is used for development modes and "production" for production servers.

Created on , last edited on