feat: add transformations

Fixes #9
This commit is contained in:
Karl-Philipp Wulfert
2019-07-10 16:12:21 +02:00
parent d05fd8a2a5
commit ddbe00d2a5
17 changed files with 415 additions and 175 deletions

View File

@@ -3,11 +3,12 @@
[![pipeline status](https://gitlab.com/openstapps/logger/badges/master/pipeline.svg)](https://gitlab.com/openstapps/logger/commits/master)
[![coverage report](https://gitlab.com/openstapps/logger/badges/master/coverage.svg)](https://gitlab.com/openstapps/logger/commits/master)
This is a simple logger for TypeScript projects with colors for console output.
This is a simple logger for TypeScript projects with transformations for the log output.
Logs are only printed if their log level is equal or higher than the defined log level.
## Log Levels
Available log levels are:
- 1 - INFO
- 2 - LOG
@@ -25,15 +26,18 @@ If you want to use logger in production (`NODE_ENV=production`) and allow all tr
`ALLOW_NO_TRANSPORT` to `true`.
## SMTP
This class also provides a simple implementation of an SMTP transport which can be used as a
`TransportWithVerification` for the logger. You can use this to transport errors of the logger or to transport mails
of your own monitoring solution.
### Usage
You can instatiate it with a config or it will check for a config in the environment variables. Environment variables
can overwrite the actual config values.
Environment variables are:
* SMTP_AUTH_USER: SMTP username
* SMTP_AUTH_PASSWORD: SMTP password
* SMTP_HOST: SMTP host
@@ -43,3 +47,15 @@ Environment variables are:
* SMTP_SENDER_MAIL: sender of the mail
* SMTP_SENDER_NAME: name of the sender
* SMTP_SECURE: `true` to enable tls
## Transformations
By default the logger will only add the log level to the message.
You can change this behavior by setting other Transformers via `Logger.setTransformations`. If you do so, mind the order of the transformers.
You may choose from the following:
* `AddLogLevel`, which prepends the output with the log level
* `Colorize`, which colorizes the output according to the log level
* `Timestamp`, which prepends a timestamp to the output