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

adding marker property to ExLogRecord #3

Merged
merged 1 commit into from
Mar 15, 2021

Conversation

dfa1
Copy link
Contributor

@dfa1 dfa1 commented Mar 14, 2021

Hi @dmlloyd,

@jamezp pointed out to move jboss-logging/jboss-logmanager#333 here, so please have a look and let's discuss. This change should be backward compatible (adding a new field).

This new property will be used to propagate the Marker to the actual
logging library. Since both SLF4J and Log4j define a different Marker
class without any common interface, here an Object is used.

This is a proposal to be able to receive the SLF4J (or log4j) Marker instance in the actual logging "driver". My use-case is to use it in a custom JsonProvider for quarkus:

@Singleton
public class MyJsonProvider implements JsonProvider {

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

Also slf4j-jboss-logmanager should be adapted too (i.e. to avoid MarkerIgnoringBase):

 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.setMarker(marker); <--- new code 
        logger.logRaw(rec);
    }

@jamezp
Copy link
Contributor

jamezp commented Mar 15, 2021

I do wonder if we should call it something other than xxxMarker() in case we do ever decide to implement a marker. We could use something similar to MDC for this I would think as well.

@dfa1
Copy link
Contributor Author

dfa1 commented Mar 15, 2021

I'm open to suggestions! :-)

@jamezp
Copy link
Contributor

jamezp commented Mar 15, 2021

I was trying to think of one and really couldn't :) Maybe it could be something like "userContext" or "recordContext". Maybe that's not great though.

@dmlloyd
Copy link
Owner

dmlloyd commented Mar 15, 2021

I think having it just be "marker" makes sense. By explicitly being agnostic about it, we don't constrain the user at all. If we ever come up with a separate marker concept, I'd probably look for a different name than "marker" - or just overload the existing marker one more time.

@dfa1
Copy link
Contributor Author

dfa1 commented Mar 15, 2021

hi @dmlloyd,

thanks for your time! I reverted Marker to be just Object. The only downside I see is that, since ExtLogMarker is serializable, a non-serializable Marker will break it, right?

This new property will be used to propagate the Marker to the actual
logging library. Since both SLF4J and Log4j define a different Marker
class without any common interface, here an Object is used.
@dfa1 dfa1 force-pushed the support-for-markers branch from 6e6da4d to 62e8c9e Compare March 15, 2021 19:47
@dmlloyd
Copy link
Owner

dmlloyd commented Mar 15, 2021

hi @dmlloyd,

thanks for your time! I reverted Marker to be just Object. The only downside I see is that, since ExtLogMarker is serializable, a non-serializable Marker will break it, right?

Right, but only if the record is actually serialized and there is a non-serializable marker on it. The same thing could happen with an MDC value, for example. But since the majority of users do not serialize their log records (at least, not using Java serialization), the possibility is of minimal concern.

@dmlloyd dmlloyd merged commit 85cb235 into dmlloyd:master Mar 15, 2021
@dmlloyd
Copy link
Owner

dmlloyd commented Mar 15, 2021

Thanks!

@dfa1 dfa1 deleted the support-for-markers branch March 16, 2021 06:35
@dfa1
Copy link
Contributor Author

dfa1 commented Mar 16, 2021

thank you @dmlloyd @jamezp

Now I would need a release of this artifact to be able to use in the SLF4J binding for jboss-logging. What is the dependency/repository used by quarkus?

@dmlloyd
Copy link
Owner

dmlloyd commented Mar 16, 2021

This is it. But IIUC you'd need more than a release of this project; you'd also need @jamezp to accept the corresponding change to the slf4j-jboss-logmanager and log4j-jboss-logmanager projects - which I can't envision without jboss-logging/jboss-logmanager#333 being revived. So where does that leave us?

@dfa1
Copy link
Contributor Author

dfa1 commented Mar 16, 2021 via email

@dmlloyd
Copy link
Owner

dmlloyd commented Mar 16, 2021

Yeah you'd need it to be the same. And James will have to agree as well.

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.

3 participants