question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create an abstraction for a LoggingContext containing request properties

See original GitHub issue

Currently, armeria natively exports many useful attributes to logback logs

https://github.com/line/armeria/blob/master/logback/src/main/java/com/linecorp/armeria/common/logback/BuiltInProperty.java

But since these are hard-coded into the logback implementation itself, it can’t be reused for log4j users. Could we add to a RequestContext a layer that accumulates key/value pair that logging layers can read without special processing?

Here is a similar idea, but misses out on armeria’s built-in logging, which would be very tedious to duplicate.

https://github.com/curioswitch/curiostack/blob/master/common/server/framework/src/main/java/org/curioswitch/common/server/framework/logging/RequestLoggingContext.java#L39

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
trustincommented, Dec 31, 2018

IMO core API seems fine since we have many logging features there already, like LoggingService. To be honest, I was surprised to find https://github.com/line/armeria/blob/master/logback/src/main/java/com/linecorp/armeria/common/logback/RequestContextExporter.java in logback package since it doesn’t touch any logback APIs at all and it’s a ton of code to possibly duplicate into log4j implementation.

Creating a shared artifact for that or just duplicating might be fine

Perhaps we could clean up the common export logic a little bit and move it to armeria.common or into a utility method of RequestContext? e.g. Map<String, String> ctx.exportProperties(...properties to export...)

but also I do think there’d be a lot of convenience if we could offer requestCtx.logCtx().put("entityId", id) so it’s very easy for business logic to add additional tags without worrying about threads. Does that make it worth putting it into core?

RequestContext already extends AttributeMap which overlaps with it to some extent. How about replacing AttributMap with our own interface which defines a key which tells if its value needs to be exported to logging framework or to the String representation of RequestContext? e.g.

private static AttributeKey<String> ENTITY_ID =
        AttributeKey.of("entityId", /* exported */ true);
private static AttributeKey<ComplexObject> COMPLEX_OBJECT = 
        AttributeKey.of("...", true, complexObject -> "stringified: " + complexObject.propX());
0reactions
trustincommented, Dec 23, 2019

The groundwork for adding support for Log4J2 is now done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

LoggingContext Class - PostSharp 6.10 Documentation
Gets the LogEventData (i.e. the source of logging properties) associated with the current LoggingContext. Public property, HierarchicalContextIdInfo. Exposes ...
Read more >
Spring Boot Logging Best Practices Guide - Coralogix
We've looked at how most logging concerns (formatting, destinations, cross-cutting logging, context and unit tests) can be abstracted away from ...
Read more >
Conversation Logging - JAICF documentation
This abstraction enables you to hide sensitive data before it's logged. ... Once request is processed and all reactions are created, JAICF obfuscates...
Read more >
Contextual Logging in NodeJS - Xebia
These serverless alternatives often go hand in hand with NodeJS. ... Let's create a little ExpressJS application written in TypeScript to ...
Read more >
netcommon-developer Mailing List for Common Infrastructure ...
I have implemented logging context abstractions for NLog and log4net (and also for ... for the logical properties to be propagated along the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found