[go: nahoru, domu]

Skip to content
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

How to use on AWS Lambda #637

Open
cloudlena opened this issue Sep 14, 2018 · 4 comments
Open

How to use on AWS Lambda #637

cloudlena opened this issue Sep 14, 2018 · 4 comments

Comments

@cloudlena
Copy link

I'm trying to use zap on AWS Lambda. With the following configuration:

logger, err := zap.NewProduction()
if err != nil {
	log.Fatalf("error creating logger: %s", err)
}
...

I am getting the following error when running it on Lambda:

error syncing logger: sync /dev/stderr: invalid argument

when checking for an error on logger.Sync:

...
defer func() {
	err := logger.Sync()
	if err != nil {
		log.Fatalf("error syncing logger: %s", err)
	}
}()

So I tried changing the config to the following:

logConfig := zap.NewProductionConfig()
logConfig.OutputPaths = []string{"stdout"}
logger, err := logConfig.Build()
if err != nil {
	log.Fatalf("error creating logger: %s", err)
}

which now gives me another error (from the same call to logger.Sync):

error syncing logger: sync /dev/stdout: invalid argument

As far as I know, Lambda supports and recommends logging to stdout and stderr so I don't understand why it's not working. Is there a recommended way of fixing this?

@jacknagz
Copy link
jacknagz commented Oct 2, 2018

This works for me:

func init() {
	Logger, LoggerErr = zap.NewProduction()
	if LoggerErr != nil {
		log.Fatalf("Cannot initialize zap logger: %v", LoggerErr)
	}
	defer Logger.Sync()
}

@kaushikthedeveloper
Copy link

Any updates on this? Facing a similar issue.

Ping : @akshayjshah

@dnozdrin
Copy link

Seems the issue is directly related to this one #328

@prashantv
Copy link
Collaborator

If you are using the a standard WriteSyncer, then there's no buffering done by zap, so the Flush is not necessary.

The underlying issue is related to #328 -- unfortunately the Flush is not supported by os.Stdout and os.Stderr on Linux, and so it has to be ignored somewhere.

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

No branches or pull requests

5 participants