I have my own small project (module) that I want to pour into open source, but it depends on my custom logger (SLogger). SLogger is a superstructure over log4j2. I want to break the dependency of my SLogger module so that people can choose their own logging library. How can I bring my SLogger under the slf4j facade?
- As far as I understand, it will be enough to use Logger from the necessary packet. - etki
- And what prevents directly using slf4j? Depending on which implementation is present for it, that logger will be used. - Artem Konovalov
- @ArtemKonovalov because my project consists of a heap of modules, and it is really very large. (about 1 million lines of code) Logging everywhere on slf4j is a very big job. The question can even be reformulated. How to write your implementation of slf4j? In fact, the implementation has already been written and it must be adjusted to the slf4j facade. - GermanSevostyanov
- @Etki, the fact is that I use my custom SLogger in the whole project (it consists of 25 different modules), which is add-on for log4j. But now I want to bring some modules into open-source, but without dependence on my SLogger (not everyone wants to use my bible for logging). So how would you like to bring my logger under the slf4j facade? - GermanSevostyanov
- @GermanSevostyanov and you can not pull in the class wrapper SLogger methods not log4j but slf4j? or something I do not understand. - Artem Konovalov
|
1 answer
I will not give clear instructions. But I can advise where to dig. Slf4j has several implementations . Among them is slf4j-simple, which redirects the entire output to System.err. You can delve into its source (there are only 5 classes) and rewrite it to fit your needs. With regards to dependencies, you can distribute the jar archive or publish it in the maven central .
UDP template for your own implementation of slf4j api
package org.slf4j.impl; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.spi.LoggerFactoryBinder; public class StaticLoggerBinder implements LoggerFactoryBinder {
private final static StaticLoggerBinder SINGLETON = new StaticLoggerBinder(); private final ILoggerFactory loggerFactory; private StaticLoggerBinder() { loggerFactory = new CustomLoggerFactoryImp(); } @Override public ILoggerFactory getLoggerFactory() { return loggerFactory; } @Override public String getLoggerFactoryClassStr() { return "CustomLoggerFactory"; } public static StaticLoggerBinder getSingleton() { return SINGLETON; } private static class CustomLoggerFactoryImp implements ILoggerFactory { @Override public Logger getLogger(String name) { return /*"реализация org.slf4j.Logger"*/ null; } }} - Yes, already downloaded both simple and NOP. I will dig in that direction :) And no, not just delegation of methods :) Thanks. - GermanSevostyanov
- I think when I finish I will issue as an answer, your answer is like) - GermanSevostyanov
- It would be curious to look. from the heart) - Artem Konovalov
- There is a difficult task :) I have methods that are not provided by the slf4j facade, it turns out they can not be adjusted to fit? After all, people will still be able to use only what if slf4j or there is some workaround? :) - GermanSevostyanov
- That's why it’s a general api, naturally there won't be any specific features of logging libraries - Artem Konovalov
|