public class RuntimeLoggerFactoryImpl extends Object implements RuntimeLoggerFactory
RuntimeLoggerFactoryImpl
by providing a
"runtimelogger-config.xml" file in one of those locations relative to your
main class's location:
Given your main class's JAR file resides in the folder /opt/app/lib, then the valid locations for the "runtimelogger-config.xml" file are:
In case you pass a JVM argument via "-Dconfig.dir=path_to_your_config_dir"
(where path_to_your_config_dir stands for the path to the directory where you
placed configuration files such as the "runtimelogger-config.xml" file), then
your path_to_your_config_dir is placed first in the list of configuration
directories to look at (in case the directory exists).See
RuntimeConsts.SYS_PROP_CONFIG_DIR
and
RuntimeUtility.toAppConfigDirs()
.
The "runtimelogger-config.xml" configuration is deadly simple:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<config>
<root config-class="org.refcodes.logger.impls.RuntimeLoggerImpl" logPriorityName="INFO" name="*">
<logger config-class="org.refcodes.logger.impls.SystemLoggerImpl" />
</root>
<com>
<acme config-class="org.refcodes.logger.impls.RuntimeLoggerImpl" logPriorityName="INFO" name="AcmeLogger">
<logger config-class="org.refcodes.logger.impls.SystemLoggerImpl" />
</acme>
</com>
</config>
The XML element nesting represents the Java package for which the therein
configured RuntimeLogger
is responsible; e.g. a log issued from
inside a class located in the package "com.acme" (or in one of its
sub-packages) will be handled by the "AcmeLogger". In case no logger is found
for a given package, then the root logger found in the <root> ...
</root> element is used. Useful to know that a logger for a package
namespace is only created once.
If you like logs colored nicely with ANSI escape codes, then you will love the ConsoleLoggerSingleton:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<config>
<root config-class="org.refcodes.logger.impls.RuntimeLoggerImpl" logPriorityName="INFO" name="*">
<logger config-class="org.refcodes.logger.alt.console.impls.ConsoleLoggerSingleton" />
</root>
</config>
Make sure to include the "refcodces-logger-alt-console"
dependency in your build setup to include the "ConsoleLoggerSingleton"
logger.Modifier | Constructor and Description |
---|---|
protected |
RuntimeLoggerFactoryImpl() |
Modifier and Type | Method and Description |
---|---|
RuntimeLogger |
createInstance() |
RuntimeLogger |
createInstance(Properties aProperties) |
RuntimeLogger |
createInstance(String aIdentifier) |
RuntimeLogger |
createInstance(String aIdentifier,
Properties aProperties)
The provided identifier represents a level hierarchy as defined in the
RuntimeLoggerConsts.RUNTIME_LOGGER_CONFIG XML file. |
public RuntimeLogger createInstance()
createInstance
in interface org.refcodes.factory.TypedFactory<RuntimeLogger>
public RuntimeLogger createInstance(Properties aProperties)
createInstance
in interface org.refcodes.factory.TypedFactory<RuntimeLogger>
public RuntimeLogger createInstance(String aIdentifier)
createInstance
in interface org.refcodes.factory.TypedLookupIdFactory<RuntimeLogger,String>
public RuntimeLogger createInstance(String aIdentifier, Properties aProperties)
RuntimeLoggerConsts.RUNTIME_LOGGER_CONFIG
XML file. The level
hierarchy is actually the path to the XML element providing the
RuntimeLogger
's configuration. Each level is separated by the
succeeding level with a dot "." as defined by the
DelimeterConsts.HIERARCHY_DELIMETER
char value. The root logger's
level hierarchy (XML path) is defined by the
RuntimeLoggerConsts.ROOT_LOGGER_ELEMENT_PATH
; at the time of this
writing it was set to "org.refcodes.logger.runtimeLogger". The properties
are currently ignored.createInstance
in interface org.refcodes.factory.TypedLookupIdFactory<RuntimeLogger,String>
Copyright © 2016. All rights reserved.