cloudformation-cli-go-plugin icon indicating copy to clipboard operation
cloudformation-cli-go-plugin copied to clipboard

Logging unavailable at runtime unless `logging` tag passed to compile

Open jamestelfer opened this issue 5 years ago • 8 comments

If you create a new project using the Go template, no logging will be received unless the project is compiled with the logging tag.

This can be done by changing the makebuild file to include the tag, or running make with the TAGS environment variable defined:

TAGS=logging make

How can this be made more obvious?

Suggestions:

  • add a comment in the generated makebuild file to note the values accepted by TAGS and the effect
  • add a comment in the generated resource.go describing how logging can be enabled
  • add documentation on the README

I found out the way to enable logging via a hint in https://github.com/aws-cloudformation/cloudformation-cli/issues/391; this could be made more discoverable for others.

jamestelfer avatar Dec 22 '20 05:12 jamestelfer

We also stumbled upon this today. Wondering why logging isn't enabled by default? Deploying a custom Lambda that doesn't log anything is surprising, to say the least.

mlafeldt avatar Jul 28 '21 16:07 mlafeldt

We also stumbled upon this today.

We followed the instructions of adding TAG=logging to the build process, but the CloudWatch Group was not created. Is there anything else that needs to be toggled as well, to see the logs of the custom resource?

isimluk avatar Jun 21 '22 15:06 isimluk

@isimluk I'm having the same problem, did you get a resolution?

msummers-nr avatar Jun 13 '23 12:06 msummers-nr

What would make this more obvious? README doc updates? Or do you think it would be better to remove the tagging and enable logging by default?

kddejong avatar Jun 13 '23 15:06 kddejong

@kddejong My vote is README update including IAM Role settings- I have yet to get this to work.

It would be good to know if the resulting CloudWatch writer is compatible with logrus as well.

msummers-nr avatar Jun 13 '23 15:06 msummers-nr

but the CloudWatch Group was not created

I checked my configuration -- it was a long time ago, and I don't remember doing anything special to get logging, and my IAM roles don't mention CloudWatch. Make sure you are passing the TAGS=logging to make correctly would be my advice.

It would be good to know if the resulting CloudWatch writer is compatible with logrus as well.

I use zerolog, but it might be helpful to you. The framework sets up a Cloudwatch logger that is attached to the Go logging framework, so my configuration routes zerolog logs through to the Go logging system.

		// Pass the Go logging framework writer as the target for zerolog. The CFN resource
		// framework sets a custom Cloudwatch Logs writer on
		// "log", so we need to use this to write zerolog output to Cloudwatch
		// Logs too.
		log.Logger = zerolog.New(golog.Writer()).
			With().
			Str("handler", handlerName).
			Logger()

jamestelfer avatar Jun 13 '23 23:06 jamestelfer

@isimluk I'm having the same problem, did you get a resolution?

I am sorry, I cannot remember. It has been a good while. Check you have proper permissions given to the lambda, that may be the root cause of not seeing any logs. Here is the lambda that I published a while ago and works fine.

isimluk avatar Jun 14 '23 08:06 isimluk

I have CloudWatch logging working through logrus when the Resource is executed via a stack.

Anyone able to grab their logging when test-type is run? The best I can tell cfn is getting in the way.

Code snippet for logrus

import(
   log "github.com/sirupsen/logrus"
   ol "log"
)
....
         log.SetOutput(ol.Writer())

msummers-nr avatar Jun 14 '23 18:06 msummers-nr