- java.lang.Object
-
- org.refcodes.logger.RuntimeLoggerFactoryImpl
-
- All Implemented Interfaces:
org.refcodes.factory.LookupFactory<RuntimeLogger,String>,org.refcodes.factory.TypeFactory<RuntimeLogger>,RuntimeLoggerFactory,org.refcodes.mixin.TypeAccessor<RuntimeLogger>
- Direct Known Subclasses:
RuntimeLoggerFactorySingleton
public class RuntimeLoggerFactoryImpl extends Object implements RuntimeLoggerFactory
You configure yourRuntimeLoggerFactoryImplby providing a "runtimelogger.ini" file (see "http://www.refcodes.org/refcodes/refcodes-logger") in one of those locations relative to your main class's location:- .
- ./config
- ./etc
- ./settings
- ./.config
- ./.settings
- ../config
- ../etc
- ../settings
- ../.config
- ../.settings
runtimelogger.ini" file are:- /opt/app/lib
- /opt/app/lib/config
- /opt/app/lib/etc
- /opt/app/lib/settings
- /opt/app/lib/.config
- /opt/app/lib/.settings
- /opt/app/config
- /opt/app/etc
- /opt/app/settings
- /opt/app/.config
- /opt/app/.settings
runtimelogger.ini" 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).SeeSystemProperty.CONFIG_DIRandConfigLocator.getFolders(). The "runtimelogger.ini" configuration is deadly simple:[root] runtimelogger=org.refcodes.logger.RuntimeLoggerImpl runtimelogger/logPriority=INFO runtimelogger/logger=org.refcodes.logger.SystemLogger [com.acme] runtimelogger=org.refcodes.logger.RuntimeLoggerImpl runtimelogger/logPriority=INFO runtimelogger/name=com.acme runtimelogger/logger=org.refcodes.logger.SystemLogger
The XML element nesting represents the Java package for which the therein configuredRuntimeLoggeris 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:
Make sure to include the "refcodces-logger-alt-console" dependency in your build setup to include the "ConsoleLoggerSingleton" logger.<?xml version="1.0" encoding="ISO-8859-1" ?> <config> <root config-class= "org.refcodes.logger.RuntimeLoggerImpl" logPriorityName="INFO" name="*"> <logger config-class= "org.refcodes.logger.alt.cli.ConsoleLoggerSingleton" /> </root> </config>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.TypeAccessor
org.refcodes.mixin.TypeAccessor.TypeBuilder<T extends Object,B extends org.refcodes.mixin.TypeAccessor.TypeBuilder<T,B>>, org.refcodes.mixin.TypeAccessor.TypeMutator<T extends Object>, org.refcodes.mixin.TypeAccessor.TypeProperty<T extends Object>
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedRuntimeLoggerFactoryImpl()Instantiates a new runtime logger factory impl.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RuntimeLoggercreateInstance()RuntimeLoggercreateInstance(String aIdentifier)RuntimeLoggercreateInstance(String aIdentifier, Map<String,String> aProperties)The provided identifier represents a level hierarchy as defined in theRuntimeLogger.RUNTIME_LOGGER_CONFIGXML file.RuntimeLoggercreateInstance(Map<String,String> aProperties)static RuntimeLoggerfromConfigurationFile(String aElementPath, String aConfigFileName)Loads the configuredRuntimeLoggerfrom the given configuration file.
-
-
-
Method Detail
-
createInstance
public RuntimeLogger createInstance()
- Specified by:
createInstancein interfaceorg.refcodes.factory.TypeFactory<RuntimeLogger>
-
createInstance
public RuntimeLogger createInstance(Map<String,String> aProperties)
- Specified by:
createInstancein interfaceorg.refcodes.factory.TypeFactory<RuntimeLogger>
-
createInstance
public RuntimeLogger createInstance(String aIdentifier)
- Specified by:
createInstancein interfaceorg.refcodes.factory.LookupFactory<RuntimeLogger,String>
-
createInstance
public RuntimeLogger createInstance(String aIdentifier, Map<String,String> aProperties)
The provided identifier represents a level hierarchy as defined in theRuntimeLogger.RUNTIME_LOGGER_CONFIGXML file. The level hierarchy is actually the path to the XML element providing theRuntimeLogger's configuration. Each level is separated by the succeeding level with a dot "." as defined by theDelimiter.NAMESPACEchar value. The root logger's level hierarchy (XML path) is defined by theRuntimeLogger.ROOT_LOGGER_ELEMENT_PATH; at the time of this writing it was set to "org.refcodes.logger.runtimeLogger". The properties are currently ignored.- Specified by:
createInstancein interfaceorg.refcodes.factory.LookupFactory<RuntimeLogger,String>
-
fromConfigurationFile
public static RuntimeLogger fromConfigurationFile(String aElementPath, String aConfigFileName) throws LoggerInstantiationRuntimeException
Loads the configuredRuntimeLoggerfrom the given configuration file. Various locations as well file endings are probed as of theRuntimePropertiesas well as of theConfigLocator.ALLdefinition.- Parameters:
aElementPath- The path (package) for which to create the logger.aConfigFileName- The (base) file name of the configuration file.- Returns:
- The according logger.
- Throws:
LoggerInstantiationRuntimeException- Thrown in case instantiating aLogger(RuntimeLogger) failed,
-
-