-
Notifications
You must be signed in to change notification settings - Fork 150
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
bug(logger): standardize extra input logging #565
Comments
The proposal in the "expected behaviour" section is not final and can be discussed. Ideally would appreciate whoever picks up the issue to engage with the maintainers to discuss options and implementation before going for a PR. |
@dreamorosi In the expected behavior, this example:
Do you actually mean this?
|
@ijemmy indeed and good catch. Copy/paste errors, I've corrected the OP. |
@ijemmy I'd like to take this one. Let me describe my proposal for the log format for extra strings and arrays. I'll get back to you for a review before implementing it. |
@ijemmy @dreamorosi Here's my proposed log format for these use cases. In a nutshell: every additional input without a key gets an auto-generated key Examples:
Note: Lambda PowerTools for Python and Java only accept additional input with explicitly specified keys (aka dict). I we'd align to them, that would be a breaking change in our API. Should we consider this? |
Thanks for detailing your proposal @AWSDB. // 1) Message as string
logger.info('This is the message value');
// 2) Message as string, object
logger.info('This is the message value', { extra: 'parameter' });
// 3) Message as string, object, object, ...
logger.info('This is the message value', { parameterOne: 'foo' }, { parameterTwo: 'bar' });
// 4) Object (that contains the message key)
logger.info( { message: 'This is the message value', extra: 'parameter' });
// 5) Message as string, error
logger.info('This is the message value', new Error('Something happened!') );
// 6) Message as string, error with custom key
logger.info('This is the message value', { myCustomErrorKey: new Error('Something happened!') }); The current logic of the logger assumes that if you pass a string as first parameter, that string represents the value of the message key in the structured logs. You can achieve the same by passing an object with a message key. |
Thanks for the explanation @saragerion. type LogItemExtraInput = Array<Error | LogAttributes | unknown>; As I mentioned above, we could restrict the extra objects to the cases you describe ( Please let me know which way you'd prefer: a breaking API change (+updating the docs) or a non-breaking change proposed by @dreamorosi. |
Thanks @saragerion for clarifying, I was not aware that examples 3 & 4 in your code snippet were possible. From my side I just wanted to highlight again that I don't have any strong preference towards my proposal. What I would expect as user would be to either the types telling me I cannot pass a string or else if it's accepted to not break it down into characters in the JSON. Also definitely consistency with other runtimes is something we should keep in mind. |
I've discussed with maintainers. We have to make a trade-off here. And we prefer consistency with other PowerTool even it means a breaking change (as we're still in Beta). Here's the scope of this issue:
|
I believe we can resolve this one, because the corresponding PR is already merged. |
|
Bug description
As described in the docs
Logger
accepts a second parameter that allows to append additional keys and values in a single log item.This works when passing an object, for example
logger.info('my-message', { data: 'my-value' });
results in:But when passing directly a string, like:
logger.info('my-message', 'my-value');
it results in this:Likewise, when passing an array,
logger.info('my-message', ['my-value', 'my-value2']);
it results in:Expected Behavior
Have a consistent behaviour across data types, potentially using a default key when a string or array are passed, i.e.
logger.info('my-message', 'my-value');
Current Behavior
Expand below to see full CloudWatch log output
Possible Solution
Check data types and treat them accordingly.
Steps to Reproduce
@aws-lambda-powertools/logger
in your LambdaEnvironment
Related issues, RFCs
N/A
The text was updated successfully, but these errors were encountered: