Skip to content

message located last at the log line. #138

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

Closed
ypolon7kiy opened this issue Aug 27, 2020 · 10 comments
Closed

message located last at the log line. #138

ypolon7kiy opened this issue Aug 27, 2020 · 10 comments
Labels
feature-request feature request good first issue Good for newcomers

Comments

@ypolon7kiy
Copy link

ypolon7kiy commented Aug 27, 2020

Is your feature request related to a problem? Please describe.
I'm always frustrated when i try to read logs, but the message is located at the end of line, so thre is always need to open each line in CloudWatch.

In that way one cannot read the app flow logic easily.

Describe the solution you'd like
move message to the start of the line, or after timestamp.

Can be solved in:
logger/formatter.py
format(self, record)

PROBLEM EXAMPLE:
{"timestamp": "2020-08-27 08:55:33,265", "level": "INFO", "location": "lambda_handler:9", "service": "aaa", "sampling_rate": 0.0, "cold_start": true, "function_name": "TestPeriod", "function_memory_size": "128", "function_arn": "arn:aws:lambda:eu-central-1:508054367788:function:TestPeriod", "function_request_id": "d55d25b5-db25-446d-9c04-10cc79800981", "order_id": "aaa", "message": {"operation": "collect_payment"}}

@ypolon7kiy ypolon7kiy added feature-request feature request triage Pending triage from maintainers labels Aug 27, 2020
@heitorlessa heitorlessa added area/logger good first issue Good for newcomers and removed triage Pending triage from maintainers labels Aug 27, 2020
@heitorlessa
Copy link
Contributor

Hi Yuriy - Thanks for raising your first issue and feature request under the AWS Labs org :)

I see what you mean, and hopefully that's a quick fix:

I've just tagged as a good first contribution issue in case you or anyone reading this later want to give this a try. Otherwise, I'll implement this later next week :)

@michaelbrewer
Copy link
Contributor

@heitorlessa @ypolon7kiy I fixed this in #140. I think the order should be timestamp,level,location,message and the rest.

@michaelbrewer
Copy link
Contributor

@heitorlessa @ypolon7kiy - otherwise if there is a strong preference i could make it timestamp,message,level,location.

But having the message after the location is handy to match things up to the implementation code.

@heitorlessa
Copy link
Contributor

I think the challenge @ypolon7kiy is having is that he's using the standard CloudWatch Logs console, and the line preview shows only the first key (timestamp) hence the ask for bringing up as first.

That's why DAZN Lambda Powertools for JS does this: https://github.com/getndazn/dazn-lambda-powertools/blob/d870d55bbbe9851705b1e860e4a45d2968edaaf5/packages/lambda-powertools-logger/index.js#L82

I'd wait for @ypolon7kiy to chime back and confirm the challenge he's having.

Customers using ELK, CloudWatch Log Insights, and any advanced Log Analytics tool allows you to change the order as you see fit regardless of how the logs have been ingested, but I still suspect that's not the case with Yuriy

@ypolon7kiy
Copy link
Author

Hi @heitorlessa and @michaelbrewer .
Thank you for the response.
I would put actually timestamp more closely to the end because in CloudWatch logs it looks like :

2020-08-27T12:21:21.894+03:00 | {"timestamp": "2020-08-27 09:21:21,894", "level": "INFO", "location": "lambda_handler:25", "service": "aaa", "sampling_rate": 0.0, "cold_start": false, "function_name": "TestPeriod", "function_memory_size
.....

So the timestamp appearing twice at the beginning.

But what you decide.

@michaelbrewer
Copy link
Contributor

michaelbrewer commented Aug 27, 2020

@ypolon7kiy @heitorlessa i updated it to be configurable as well and the default is "level", "location", "message", "timestamp" But if you want to change it just pass through format_key to the logger ie:

>>> logger = Logger(format_key=["message"])
>>> logger.info("Message")
{'message': 'Message', 'level': 'INFO', 'location': 'test_log_dict_key_custom_seq:139', 'timestamp': '2020-08-27 11:40:33,718', 'service': 'service_undefined', 'sampling_rate': 0.0}

@michaelbrewer
Copy link
Contributor

@ypolon7kiy - you should check out #140 and see if this fits in with what you are expecting.

@heitorlessa
Copy link
Contributor

@ypolon7kiy could you tell me whether the docs match your expectation?

https://github.com/awslabs/aws-lambda-powertools-python/pull/148/files

Once merged, this feature and docs will be available in the next release (1.5.0)

@ypolon7kiy
Copy link
Author

@heitorlessa
Yes, all looks fine.
Thanks

@heitorlessa heitorlessa added pending-release Fix or implementation already in dev waiting to be released and removed pending-release Fix or implementation already in dev waiting to be released labels Aug 31, 2020
@heitorlessa
Copy link
Contributor

This has now available in 1.5.0 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request feature request good first issue Good for newcomers
Projects
Development

No branches or pull requests

3 participants