Skip to content

Custom configuration for your Slf4j logger #475

Description

@ctrleno

Hi,

I hope this issue finds you well! :)

I am reaching out to see if there is a way to have a custom configuration when using Slf4j without the need to create a custom logger. Not sure if this use case can be considered specific enough to the point that it wouldn't bring value to the community, below I will explain the use-case and discuss further.

Let's say I have a controller, service, or any format of a class, I am using SLF4J for logging.

@Slf4j
public class ServiceBaseImpl implements MyInterface{
    public void myMethod(Param param){
      log.info("Logging param {}", param);
    }
}

What I mean by custom configuration is that I want to enforce a specific logging contract to my team that contributes to the services that we work on, so that we have one, single logging contract that everyone is enforced to use because the configuration says so.

Let's say I have multiple services, and I want the logging to be the same on all of them, by logging I mean the format and what is logged, asking someone to just do it, not really effective as after some time people tend to just log what they need so I was thinking to have something like the following:

@Slf4j
public class ServiceBaseImpl implements MyInterface {
    
    /*
        * Example method to demonstrate logging
        * request-in - indicates the start of a request processing, as a request comes in
        * start - indicates the beginning of the method execution
        * service-name - specifies the name of the service being invoked
        * message - provides additional context or information about the request
        * myParam - parameter passed to the method
     */
    public void myMethod(String myParam) {
        log.info("request-in", "start", "service-name", "message", myParam...)
    }
}

These parameters would always be required based on a specific configuration created for the SLF4J logging in that specific application.

The configuration would be something like:

@Configuration
public class Slf4jLoggingConfiguration {

    public void configure(){
        // Configuration logic here
        // always require request position logging
        // always require beginning or end of method execution
        // always require service-name for logging
        // always require message
        // ...
    }
}

Please let me know if you need more details, as I tried to explain it the best I could. Thank you very much for everything that you do for the community! <3

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions