feat(logger): Add log level filtering#19
Conversation
src/index.ts
Outdated
| const NO_COMPRESS = env.get("SG_LOGGER_NO_COMPRESS").default("false").asBool(); | ||
| const NO_SKIP = env.get("SG_LOGGER_NO_SKIP").default("false").asBool(); | ||
| const LOG_TS = env.get("SG_LOGGER_LOG_TS").default("false").asBool(); | ||
| const LOG_LEVEL = env.get("SG_LOGGER_LOG_LEVEL").default("warn").asEnum<Level>(["debug", "info", "warn", "error"]); |
There was a problem hiding this comment.
We can discuss what the default should be.
I thought warn would be a sensible good default to avoid noisy logs on prod, by default.
There was a problem hiding this comment.
When using Advanced Logging Controls, the log level is set at the Lambda configuration level and available via process.env.AWS_LAMBDA_LOG_LEVEL.
Setting a default LOG_LEVEL to warn might interfere with the value defined in the function definition. To avoid having 2 settings defining the log level, we should set the default to AWS_LAMBDA_LOG_LEVEL if it exists and warn otherwise
There was a problem hiding this comment.
Also, if LOG_LEVEL>AWS_LAMBDA_LOG_LEVEL, only logs up-to AWS_LAMBDA_LOG_LEVEL will be used
There was a problem hiding this comment.
Interesting. How is AWS_LAMBDA_LOG_LEVEL affecting console.log?
Powertools also seems to use it and also has a POWERTOOLS_LOG_LEVEL.
I check
There was a problem hiding this comment.
I guess we can stick to AWS_LAMBDA_LOG_LEVEL and drop this PR.
I am not sure I see a benefit from custom log level env var.
There was a problem hiding this comment.
It is still useful in 2 cases:
- Lambda functions not using ALC (legacy TEXT format)
- Non Lambda environments (Fargate, ...)
DanielMuller
left a comment
There was a problem hiding this comment.
Update Readme with the new SG_LOGGER_LOG_LEVEL environment variable.
We should also add a paragraph to showcase the behavior when used together with AWS_LAMBDA_LOG_LEVEL
- SG_LOGGER_LOG_LEVEL>AWS_LAMBDA_LOG_LEVEL => max log level is AWS_LAMBDA_LOG_LEVEL
- SG_LOGGER_LOG_LEVEL<AWS_LAMBDA_LOG_LEVEL => max log level is SG_LOGGER_LOG_LEVEL
No description provided.