Extends stream.Transform
Transform.
This is a helper for our transforms to be able to process the written log data more easily.
All the need to do is extend this class and add their own format
method.
class Pretty extends require('caterpillar').Transform {
format (entry) {
return require('util').inspect(entry, {colors: true})
}
}
require('caterpillar').create()
.pipe(Pretty.create())
.pipe(process.stdout)
.log('note', 'cool times', 5)
.create(args)
Alternative way of creating an instance of the class without having to use the new
keyword.
Useful when creating the class directly from require
statements.
Alternative way of creating an instance of the class without having to use the new
keyword.
Useful when creating the class directly from require
statements.
Transform
#constructor(args)
Construct our class and pass the arguments over to setConfig
Construct our class and pass the arguments over to setConfig
#format(message)
Format the written data into whatever we want. Here is where our transformers work with the written data to enhance it.
Format the written data into whatever we want. Here is where our transformers work with the written data to enhance it.
Any
#getConfig
Get the current configuration object for this instance.
Get the current configuration object for this instance.
Object
#getInitialConfig
Get the initial configuration option. Use this to add default/initial configuration to your class.
Get the initial configuration option. Use this to add default/initial configuration to your class.
Object
#pipe(child)
Pipe this data to some other writable stream.
If the child stream also has a setConfig
method, we will ensure the childs configuration is kept consistent with parents.
Pipe this data to some other writable stream.
If the child stream also has a setConfig
method, we will ensure the childs configuration is kept consistent with parents.
stream to be piped to
stream.Writable
:
the result of the pipe operation
#setConfig(configs)
Apply the specified configurations to this instance's configuration via deep merging.
Apply the specified configurations to this instance's configuration via deep merging.
this
setConfig({a: 1}, {b: 2})
getConfig() // {a: 1, b: 2}
Extends stream.PassThrough
Logger.
This is what we write to.
It extends from PassThrough and not transform.
If you are piping / writing directly to the logger, make sure it corresponds to the correct entry format (as described in log
).
Creation
// Via class
const Logger = require('caterpillar').Logger
const logger = new Logger()
// Via create helper
const logger = Logger.create()
// Via create alias
const logger = require('caterpillar').create()
.create(args)
Alternative way of creating an instance of the class without having to use the new
keyword.
Useful when creating the class directly from require
statements.
Alternative way of creating an instance of the class without having to use the new
keyword.
Useful when creating the class directly from require
statements.
Logger
#constructor(args)
Construct our class and pass the arguments over to setConfig
Construct our class and pass the arguments over to setConfig
#getConfig
Get the current configuration object for this instance.
Get the current configuration object for this instance.
Object
#getInitialConfig
Get the initial configuration option. Default log levels are compliant with http://www.faqs.org/rfcs/rfc3164.html
Get the initial configuration option. Default log levels are compliant with http://www.faqs.org/rfcs/rfc3164.html
Object
#getLevelInfo(level)
Receive either the level name or number and return the combination.
#getLevelName(number)
Receive a level number and return the level name
#getLevelNumber(name)
Receive a level name and return the level number
#getLineInfo
The current line info of whatever called this.
#log(args)
Log the arguments into the logger stream as formatted data with debugging information.
Log the arguments into the logger stream as formatted data with debugging information.
Object
Inputs
logger.log('note', 'this is working swell')
logger.log('this', 'worked', 'swell')
Results
{
"args": ["this is working swell"],
"date": "2013-04-25T10:18:25.722Z",
"levelNumber": 5,
"levelName": "notice",
"line": "59",
"method": "Object.<anonymous>",
"file": "/Users/balupton/some-project/calling-file.js"
}
{
"args": ["this", "worked", "well"],
"date": "2013-04-25T10:18:26.539Z",
"levelNumber": 6,
"levelName": "info",
"line": "60",
"method": "Object.<anonymous>",
"file": "/Users/balupton/some-project/calling-file.js"
}
#pipe(child)
Pipe this data to some other writable stream.
If the child stream also has a setConfig
method, we will ensure the childs configuration is kept consistent with parents.
Pipe this data to some other writable stream.
If the child stream also has a setConfig
method, we will ensure the childs configuration is kept consistent with parents.
stream to be piped to
stream.Writable
:
the result of the pipe operation
#setConfig(configs)
Apply the specified configurations to this instance's configuration via deep merging.
Apply the specified configurations to this instance's configuration via deep merging.
this
setConfig({a: 1}, {b: 2})
getConfig() // {a: 1, b: 2}