Winston Decorator
A decorator version of the winston logger written completely in Typescript.
Installation
npm install winston-decorator
Usage
winston-decorator
is designed to inject a winston logger on the decorated property of the given class.
For example:
You can pass a winston.LoggerOptions
object to the decorator to specify your settings:
or you can put it on a separate settings file if you prefer to change the settings of all your loggers at once.
The logger comes with a default label set on your class name so you can always know from where your log come from. For example:
verbose: Route loaded successfullydebug: Function calledverbose: Route loaded successfullyinfo: Listening on port 8080!
but you can change it if you want, setting it on the decorator
Test environment
The logger is designed to automatically hide all the logs when testing environment is set.
To do so you have to set the process.env[NODE_ENV]
variable to "test"
(like this: NODE_ENV=test node main.js
).
But you can also opt for a custom value for the env_variable. To specify it just pass it to the decorator settings.
In this case you can run the program with NODE_ENV=my_custom_env mocha test.js
and hide all the logs from the output.
Run tests
npm test