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

support for SLF4J Markers #333

Closed

Conversation

dfa1
Copy link
Contributor

@dfa1 dfa1 commented Feb 19, 2021

Tentative implementation for:
quarkusio/quarkus#15193

The idea is to allowing passing SLF4J Marker as metadata in slf4j-jboss-logmanager:

 private void log(final Marker marker, final java.util.logging.Level level,  final String fqcn, final String message, final Throwable t, final Object[] params) {
        final ExtLogRecord rec = new ExtLogRecord(level, message, ExtLogRecord.FormatStyle.NO_FORMAT, fqcn);
        rec.setThrown(t);
        rec.setParameters(params);
        rec.setMetadata(marker); <--- todo
        logger.logRaw(rec);
    }

Then Slf4jLogger should be changed to fully implement the SLF4J logger interface (i.e. removing MarkerIgnoringBase).
The constraint is that metadata must be typed as java.lang.Object (to avoid strong and direct dependency to slf4j-api).

@dfa1
Copy link
Contributor Author

dfa1 commented Feb 24, 2021

Hi @jamezp!

any suggestion, idea or comment is welcome! :-)

@dfa1 dfa1 changed the title proposal for SLF4J support for SLF4J Markers Mar 11, 2021
@dfa1
Copy link
Contributor Author

dfa1 commented Mar 11, 2021

@jamezp I would like to provide the PR for slf4j-jboss-logmanager too (as mentioned in the initial comment). Do you see any problems with this approach?

NB: this method could be reused for log4j Marker too (https://logging.apache.org/log4j/2.x/log4j-api/apidocs/org/apache/logging/log4j/Marker.html)

@jamezp
Copy link
Member

jamezp commented Mar 11, 2021

@dfa1 Sorry for the delay on this. AIUI markers are used more for log managers right? If so I'm not sure how the JBoss Log Manager will be able to use without it's own API.

That said Quarkus itself uses a fork of this log manager which is diverged at this point. The PR might be of more use there for you.

@dfa1
Copy link
Contributor Author

dfa1 commented Mar 11, 2021

no worries, you're already mentioned that you were busy... :-)

The idea is that the SLF4J binding should be able to create a ExtLogRecord without losing the marker instance provided by the client. Then, in the JsonProvider it could be used as:

@Singleton
public class MyJsonProvider implements JsonProvider {

    public void writeTo(JsonGenerator generator, ExtLogRecord event) throws IOException {
          if (event.getMetadata() instanceof Marker) { 
               // special logic here
          }
    }
}

@dfa1 dfa1 closed this Mar 14, 2021
@dfa1 dfa1 deleted the adding-metadata-in-ext-log-record branch March 16, 2021 12:26
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

Successfully merging this pull request may close these issues.

2 participants