Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better logger name where there are no known logging backend provided #162

Open
alexei-osipov opened this issue Feb 22, 2022 · 0 comments
Open

Comments

@alexei-osipov
Copy link

Your question

Right now if the application class path does not contains a well-known logging backend (like Logback, Log4j and etc) the created logger gets fixed predefined name "com.alipay.sofa.common.log".

So if an app uses a library like SOFAJRaft and uses a not very popular Slf4j-compatible logging backend (for example, GFLog) then all logging that is produced by that library gets default logger name "com.alipay.sofa.common.log". As result, it is impossible to control logging levels of different parts of the library separately.

Example:

Logger log = LoggerSpaceManager.getLoggerBySpace("someLoggerSpace", "someLoggerName");
// Returns logger with name "com.alipay.sofa.common.log".
// "someLoggerSpace" or "someLoggerName" are not included into the logger name at all

Your scenes

We need to control logging levels for different parts of the app separately because logs from different parts have different importance levels even if there is no logging backend known by sofa-common-tools.

Your advice

I think its necessary to modify MultiAppLoggerSpaceManager.NOP_LOGGER_FACTORY to actually take in account provided logger name instead of just defaulting to a Constants.DEFAULT_LOG:

private static final AbstractLoggerSpaceFactory NOP_LOGGER_FACTORY = new AbstractLoggerSpaceFactory(
            "nop") {
        @Override
        public Logger getLogger(String name) {
            return LoggerFactory.getLogger("com.alipay.sofa.common.log." + name);
        }
    };

Ideally it would be nice to also take the space into the account but for that it would be necessary to modify MultiAppLoggerSpaceManager to create new instances of AbstractLoggerSpaceFactory instead of using single NOP_LOGGER_FACTORY if no pre-defined logging backend is found.

Alternatively, it would be nice to have support of custom logging backend so it would be possible to utilize other logging backends that are not explicitly mentioned in MultiAppLoggerSpaceManager.createILoggerFactory(...)

Environment

  • sofa-common-tools version: 1.0.12 (transitive from jraft-core:1.3.9)
  • JVM version (e.g. java -version): openjdk version "11.0.13"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant