Comments (14)
I think this is a breaking change ==> v2
from powertools-lambda-java.
This feels quite important. Is it really breaking and not a bug?
OTOH we are redoing the logging in v2 anyway, so there's a natural synergy there.
from powertools-lambda-java.
@jdoherty I'm taking this one. I'm working on the logging v2 anyway. Not sure that make sense you spend time on a pure log4j solution as I'm using slf4j now.
from powertools-lambda-java.
https://stackoverflow.com/questions/77543791/slf4j-and-log4j2-json-messages-escaped
from powertools-lambda-java.
will be part of #1435, using the PowertoolsResolver
in log4j and some custom code in JsonUtils
for logbak
from powertools-lambda-java.
Discussion with Log4J: apache/logging-log4j2#2013
from powertools-lambda-java.
@jeromevdl we should probably update this with resolution once you're done 👼
from powertools-lambda-java.
Based on the discussions with log4j guys, on this issue, and after thinking a bit more about this, we won't log messages as JSON. Instead, we'll support advanced object as additional arguments (not using MDC which is limited to Strings), and log them as JSON (when that makes sense).
Example:
Product product = new Product("id123456", "Name of the product", 234.5);
LOGGER.info("Some message", StructuredArguments.entry("key", product));
// can also use static import to make it lighter
LOGGER.info("Some message", entry("product", product));
will produce:
{
"message": "Some message",
"product": {
"id": "id123456",
"name": "Name of the product",
"price": 234.5
}
}
Note there was no {}
in the message, if you do this:
LOGGER.info("My super product={}", entry("product", product));
will produce:
{
"message": "My super product=[...]", // will use the object.toString()
"product": {
"id": "id123456",
"name": "Name of the product",
"price": 234.5
}
}
Also working on other StructuredArguments
:
entries
that will take a completeMap
array
that will take anObject... objects
json
that will take a raw json string
For the event and response, we'll use this instead of putting the event in the message.
from powertools-lambda-java.
@jeromevdl what do we need to do this - is it simply a matter of documenting this practice? I gather the user's interface here will be through SLF4j APIs.
from powertools-lambda-java.
No I need to implement some stuff. The StructureArguments
thing and how they interpreted. It is supported with the logback-logstash-encoder but that's another library to add to the project...
from powertools-lambda-java.
My thoughts on this implementation are:
Yes we are achieving the objective of printing out objects as JSON structures in the logs, which is the ultimate goal.
However the onus is now on the library user to ensure that they log this way every time they intend to log an object.
What will I do if I only want to log an object, without a string message?
Will it be LOGGER.info("{}", entry("product", product));
?
from powertools-lambda-java.
You cannot log without a message. Or you can just log an empty message, but messages are always there (it's the basic of the loggers).
you should do LOGGER.info("", entry("product", product));
but you will have an empty message in the logs...
from powertools-lambda-java.
we could actually check if the message is empty and not adding it to the log... but a log without a message is a bit weird
from powertools-lambda-java.
I am OK with this (would like to hear other views), even though I don't love the syntax.
we could actually check if the message is empty and not adding it to the log... but a log without a message is a bit weird
Agree that it would be weird to print a log message, without any message
from powertools-lambda-java.
Related Issues (20)
- Maintenance: V2 updates - review interface & propose improvements for Serialization module HOT 3
- bug: wrong version of jackson-databind in serialization module
- RFC: Replace jackson databind with jackson-jr HOT 3
- Validation module compatible with batch module HOT 2
- Unexpected error occurred when using powertools in lambda function HOT 6
- Trace Annotations not getting added if Annotation Key has a space in it HOT 11
- Putting metrics fails when POWERTOOLS_METRICS_NAMESPACE is not set HOT 3
- Logging: Trace ID not logged with Java 17 runtime HOT 1
- Feature enhancement: Create a Subsegments for operations handled by Powertools HOT 5
- Exceptions not showing in Traces HOT 1
- RFC: Introduce Version 2
- RFC: Remove support for Java 8 in V2 HOT 7
- Feature enhancement (Logger): automatically intercept Runtime exceptions, and log information HOT 7
- Log level not restored at the end of execution HOT 2
- Support batch secrets retrieval in Parameters module HOT 6
- Maintenance: update jackson and aws-xray-recorder dependencies together HOT 4
- RFC: handle batch messages in parallel in batch module HOT 13
- v2: Example logging configuration needs to be updated HOT 3
- v2 - Params builders do not supply default TransformationManager HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powertools-lambda-java.