KyleRoss / node-lambda-log

Basic logging mechanism for Node.js Lambda Functions and other AWS services, which produces logs in JSON format for easier reading through Cloudwatch Logs.
https://lambdalog.dev
MIT License
193 stars 16 forks source link

Globally silence? #25

Closed taschmidt closed 4 years ago

taschmidt commented 4 years ago

I know I can set log.options.silent = true on a particular instance of LambdaLog. But I would like to globally silence output (across ALL instances), in this case from unit tests. Is there any way to accomplish this?

Thanks! tim

KyleRoss commented 4 years ago

Unfortunately, there isn't a way to do this globally at this time. You could use an environment variable on each one of your instances to control this globally. But in order for this package to support that functionality would require a refactor to how the default options are stored. It's definitely possible, but I'd have to find the time to make the changes.

For the quick workaround you could have an environment variable such as LAMBDALOG_SILENT=true and each of your instances could use:

log.options.silent = process.env.LAMBDALOG_SILENT === 'true';
taschmidt commented 4 years ago

Thanks for the quick response! That would work. I suppose I could also also do that in either a derived class (I'm actually using Typescript) or a factory method.

KyleRoss commented 4 years ago

Glad that helps, let me know if you run into any issues!