Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Optionally add prefix to each log line to see the origin #9

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

peterlundberg
Copy link

@peterlundberg peterlundberg commented Jan 8, 2018

When multiple cloudwatch log groups are subscribed to by the same instance of this lambda it is very useful to see what line came from which log. A similar technique is commonly used when forwarding logging from Docker containers.

With this change the name of the lambda function (or rather last part of the logGroup) and the last part of the logStream is provided as a prefix to each line sent to logentries. Thus one can see which lambda and lambda "instance" lines are from. Eg with show timestamp in LE UI and logging from /aws/lambda/pelu-hello-world-test :

04 Jan 2018 17:23:04.746 <pelu-hello-world-test 881d602> START RequestId: 8a1de951-f16b-11e7-b934-b3c549c8bb88 Version: $LATEST
04 Jan 2018 17:23:19.684 <pelu-hello-world-test 881d602> 2018-01-04T16:23:03.912Z	8a1de951-f16b-11e7-b934-b3c549c8bb88	This is a INFO line from hello-world
04 Jan 2018 17:23:19.684 <pelu-hello-world-test 881d602> END RequestId: 8a1de951-f16b-11e7-b934-b3c549c8bb88
04 Jan 2018 17:23:19.684 <pelu-hello-world-test 881d602> REPORT RequestId: 8a1de951-f16b-11e7-b934-b3c549c8bb88	Duration: 0.34 ms	Billed Duration: 100 ms Memory Size: 128 MB	Max Memory Used: 20 MB

The PR is unfortunately larger than perhaps desirable as it is from a fork we use and contains a few other changes/fixes as well. It would be great to be able to share this work with others in the community.

To summarize:

  • Add prefix environment option to be able to get a <functionname stream> prefix on all lines so can see what logged each line.
  • Fix trailing newlines (strips leading and trailing or \n chars before sending)
  • Upgraded certifi 2016.09.26 -> 2017.11.05
  • Added Makefile to simplify upgrade / zip if desired
  • Default region to eu if not set in environment
  • Adjusted README accordingly

…s-cloudwatch into merge-base-changes

Conflicts:
	README.md
	le_cloudwatch.py
	le_config.py
Prefix support + latest certify + upstream changes
This handles trailing \n in log lines without encoding them to LINE_SEPERATORS and also any unintended inital spaces
@peterlundberg
Copy link
Author

Not a lot of feedback here ;)

We are considering dropping our fork https://github.com/funnel-io/le-aws-cloudwatch as we no longer have use for it or want to maintain it.

The changes with certify upgrades and improved configurability could be of use to others?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant