Skip to content


Stephan Bösebeck edited this page Jul 17, 2015 · 1 revision

Morphium used Log4J til V2.2.20, which caused some trouble in a multithreadded, heavy load environment.

Right now, there is a very lightweight implementation of a logger, that is being used for morphiums internal logging. You can use this Logger class, if you want, as it is very lightweight and easy to use. It is being configured either using MorphiumConfig, or using JVM Parameters:

  • -Dmorphium.log.level=5 would set maximum log output, e.g. DEBUG. Levels are: 0 - no logging, 1 - FATAL only, 2 - also errors, 3 - include Warnings, 4 - add info to the list, 5 - debug messages also
  • -Dmorphium.log.synced=false if set to true, the output is unbuffered, causing every message to be written instantanously (usually used with STDOUT as output)
  • -Dmorphium.log.file=FILENAME - filename might also be - or STDOUT (both meaning stadard output) or STDERR for standard error

You also can specify an suffix for those options, which represent the logger's name (usually a class or packagename). For example, would switch off all messages from this class, would switch on debugging for all messages coming from classes in that package.

Of course, you can configure the logger using MorphiumConfig, there are the following methods:

   setGlobalLogLevel(int level);
   setGloablLogFile(String fileName);
   setGlobalLogSynced(boolean sync);

   setLogLevelForPrefix(String prfx);
   setLogLevelForClass(Class cls);

   setLogFileForPrefix(String prfx);
   setLogFileForClass(Class cls);

   setLogSyncedForPrefix(String prfx);
   setLogSyncedForClass(Class cls);

All those settings might also be set using environment variables, dots replaced by underscores (in Unix like: export morphium_log_level=5)

Attention: This logger class is by design not really threadsafe, you should create an own instance for every thread. The Logger won't create any errors in multithreaded environments, but might create some strange output Attention: Also, keep in mind that every instance of Logger will hold an open link to outputfile.

The logger class is more or less compatible with Log4J (at least most of the methods are).

The configuration of the logger is only read when initialized! So if you change your config, it won't effect your logger instances.


Introduced with V2.2.23BETA3 you can define a LogDelegate to be used instead of a File, just add the Prefix class: to the filename, e.g. -Dmorphium.log.file=class:de.caluga.morphium.Log4JLoggerDelegate would use a simple Log4J implementation.

Of course you can define your own LoggerDelegate, just implement the interface de.caluga.morphium.LoggerDelegate and add your classname as file.

Attention: The log delegate will be instanciated with every new Logger instance!

You can’t perform that action at this time.