0.0.8 • Published 2 years ago
@tmz-js/logger v0.0.8
Logger
How to use
As early as possible import logger and Init:
import logger from '@tmz-js/logger';
logger.init({serviceName: nameOfService, level: logger.LogLevel.info});
init can receive the following options:
Parameter | Optional | Default | Description |
---|---|---|---|
serviceName | V | 'anonymous' | name of service |
level | V | 'warn' | log level (use LogLevel Enum) |
keepAliveInterval | V | 5000 | Keep alive time in ms |
verbose | V | False | Print all logs |
silent | V | False | Stop the printing of all logs |
prettify | V | False | Prettify all logs |
includeServiceName | V | False | Should service name be logged |
escapeJson | V | True | Should output JSON be escaped |
anywhere in your service where you would wish to log you can import logger and log as follows:
logger.log(
${log level},
${message},
${meta data object} #optional
)
Example1:
logger.log(
logger.LogLevel.warn,
'somthing went teribly wrong'
)
Example2:
logger.log(
logger.LogLevel.warn,
'somthing went teribly wrong',
{
userID: 'some user id'
}
)
You can also use one of the following methods to log:
- error
- warn
- info
- http
- verbose
- debug
- silly
Example:
logger.info('this is very informing information');
If your service contains multiple modules you may wish to create a separate logger for each module. Example:
import Logger from '@tmz-js/logger';
const logger = Logger.getLogger('amazing logger');
logger.info('information');
- note: even when using modules you should initialize the logger as soon as possible.