Params
The following params can be passed when creating a new instance of roosevelt-logger
:
methods
[Object]: A set of configs that represent logger methods that are available to use. Each config type that maps to a default log type can be set to either a boolean to enable / disable the log or an object:info
[Boolean]: Enable regular logs. Default:true
.warn
[Boolean]: Enable logging of warnings. Default:true
.verbose
[Boolean]: Enable verbose (noisy) logging. Default:false
.[custom log name]
[Object]: You can also define your own log types and specify what native log type it maps to.- API:
enable
[Boolean]: Enable this custom log. Default:true
.type
[String]: What type of native log this custom log maps to. Default:info
.- Allowed values:
info
,warn
, orerror
.
- Allowed values:
prefix
: [String]: The string that prefixes any log entry. If not set or set to a falsy value (e.g.null
, an empty string, etc), the prefix will be disabled.- Default for warnings:
⚠️
. - Default for errors:
❌
.
- Default for warnings:
color
: [String]: The color that the text will be set to using @colors/colors npm package. If not set, it will use whatever the default color is for the native type selected.
- API:
Custom type example:
{
"dbError": {
"type": "error",
"prefix": "🗄",
"color": "cyan"
}
}
The above example would create a custom log type called dbError
. It will log errors with a 🗄 prefix and cyan text color.
params
: Configuration that applies to all logger methods:disable
[Array of Strings]: Disable all logging in certain environments. Each entry can be either an environment variable or the value of theNODE_ENV
environment variable. Default:[]
.- Example usage:
['LOADED_MOCHA_OPTS']
: Disables logger when app is being run by Mocha.['production']
: Disables logger whenNODE_ENV
is set toproduction
.
- Example usage:
enablePrefix
[Boolean]: Enable prefixes which can contain emojis or other strings to be prepended to logs. This can also be toggled with theROOSEVELT_LOGGER_ENABLE_PREFIX
environment variable. Default:true
.
API
When you create an instance of roosevelt-logger
, the following properties will be available on the logger
instance:
winston
[Object]: The Winston module thatroosevelt-logger
uses internally.winstonInstance
[Object]: The specific Winston object instance instantiated byroosevelt-logger
.transports
[Object]: The default Winston transports enabled byroosevelt-logger
.enableLogging()
[Function]: Enable the logger.disableLogging()
[Function]: Disable the logger.enablePrefix()
[Function]: Enable all log prefixes.disablePrefix()
[Function]: Disable all log prefixes.createLogMethod(config)
[Function]: Programmatically create a new logger method.config
argument [Object]:name
[String]: New logger method name.type
[String]: What type of native log this custom log maps to.- Default:
info
. - Allowed values:
info
,warn
, orerror
.
- Default:
prefix
: [String]: The string that prefixes any log entry. If not set or set to a falsy value (e.g.null
, an empty string, etc), the prefix will be disabled.- Default for warnings:
⚠️
. - Default for errors:
❌
.
- Default for warnings:
color
: [String]: The color that the text will be set to using colors npm package. If not set, it will use whatever the default color is for the native type selected.
Example createLogMethod
usage:
logger.createLogMethod({
name: 'dbError',
type: 'error'
prefix: '💥',
color: 'red'
})
logger.dbError('Our whole stack is in crisis mode!')
// => 💥 Our whole stack is in crisis mode!