LogMan
Logging manager facade to allow programmatic runtime configuration while avoiding compile time dependency on the logging system
A complement to slf4j that is focused on managing the underlying logging system (things like changing the log level).
More concrete information regarding the modules themsleves is available in their sub-directories.
Is this really needed?
...and if so why doesn't it already exist? Ideally you wouldn't need runtime log level modification at all but this is for those times that are less than ideal (as rare as those may be).
slf4j is a great abstraction because logging is a ubiquitous cross cutting concern so avoiding implementation dependent code getting scattered or polluting re-usable libraries has substantial advantages for maintainability and portability. This project intends to mirror that behavior for the management of logging...but the management of logging should not be scattered and is likely only needed in one consolidated place so the value provided for maintainability and portability is dropped down to the point of being negligible.
Then why does it exist?
The above is a disclaimer that this project is scratching a very small specific itch rather than anything even remotely as valuable as slf4j, but the itch still exists. This project in particular was launched so that it could be used in a library which provided conventional behavior to a set of applications which were running on different containers with different logging subsystems. So in a nutshell this library can be useful if:
- Management of logging will be handled by the application code rather than the container or infrastructure
- Consistent management logic is desired to be used on top of multiple logging implementations
- For reasons of defense or purity the logging system should not be a direct dependency
The last point about defense is regarding the fact that once an implementation is on the classpath there is a higher chance (without some form of guard) that someone could inadvertently use the types from an implementation elsewhere in the system rather than those from slf4j, thus undermining the use of slf4j.
Finally a big motivating factor is that largely because of the more limited use this is also a far simpler project than slf4j and should require virtually no maintenance, so the ratio of cost vs. value is appropriate.
Usage
This project uses the same approach as slf4j and many other projects of having an API package which contains the interface definitions but without an implementation (or more precisely a useless implementation). The API classes should be the only ones that is referenced in client code, and then an implementation can be bound to it by simply including it on the classpath.
This can be best accomplished by defining the api package as a compile time dependency and have the desired binding provided at runtime.
A contrived example in a gradle file would be:
//In some library
dependencies {
compile 'com.mattwhipple.logman:logman-api:0.1.0'
}
//In consuming project
dependencies {
runtime 'com.mattwhipple.logman:logman-logback:0.1.0'
}Other approaches to place bindings on the classpath should work without issue.
Registering bindings
The bindings configure themselves through the Java standard
ServiceLoader system, as such the package for each binding is expected
to contain a META-INF/services/com.mattwhipple.logman.LogManBinder
file which references the binder implementation class. Existing
binders can be used as a reference.
Multiple or missing bindings
If multiple bindings are found then each of them will be registered
with the LogManFactory, and as each one is registered an appropriate
log message will be written. This behavior as a whole is officially
undefined and so the log messages should primarily serve to indicate
which binders have been registered so that any that are not the one
that is desired can be removed.
If no bindings are discovered then the logs will show no registration, and the default no-op implementation will be used. The lack of log messages (and any messages from the no-op implementation should serve as indication that an expected binding may not be able to be found.
