kttnkndy (pronounced cotton candy) is a logging tool that actually helps your work.
- Create differently named instances for different services.
- Create timers to measure performance.
var kttn = require('kttnkndy')('myInstance'); // [myInstance] Initialized.
kttn.log('Hello World!'); // 16:54:41 - [myInstance] Hello World!
var myTimer = kttn.timer('myTimer'); // 16:54:42 - [myInstance] Started timer "myTimer".
doSomething(); // Run a time-consuming function...
myTimer.end(); // 16:55:42 - [myInstance] Ended timer "myTimer", took 60.663s.
First, we'll need to initialize a kttn instance. You should do this for every service running on the same console output.
var kttn = require('kttnkndy')('main'); // Initializes a kttn instance, logs "16:54:41 - [main] Initialized."
Something you probably do in every project you build is logging. It's essential to debugging and making sure your project works.
kttnkndy makes it easy to differentiate between logging messages from different services.
kttn.log('Hello world!'); // Outputs: "16:54:41 - [main] Hello world!"
kttn.error('Uh-oh... Something happened...'); // Outputs: "16:54:41 - [main] Uh-oh... Something happened..." on stderr
To measure your project's performance, timers are essential. They measure how much time it took to do something.
In kttnkndy, it's easy to time things.
var myTimer = kttn.timer('myTimer'); // Creates a timer instance, outputs: "16:54:42 - [myInstance] Started timer "myTimer"."
doSomething();
var ms = myTimer.end(); // Ends the timer, outputs: "16:55:42 - [myInstance] Ended timer "myTimer", took 60.663s.". Returns milliseconds.
newKttnInstance is the function returned on require('kttnkndy')
.
var kttn = require('kttnkndy')('myInstance', {
showInitializedMessage: true,
timestampedLog: true
})
- instanceName - The name of the kttn instance. Appears in all log messages. (string)
- options - A KttnOptions object.
newKttnInstance returns a KttnInstance.
kttnLog is the function returned on kttn.log
.
kttn.log('Hello World!')
- message - The message to log. (string)
kttnError is the function returned on kttn.error
.
This is kttnLog, but it logs the message to stderr
.
kttnTimer is the function returned on kttn.timer
.
var timer = kttn.timer('myTimer');
- name - The name of the timer. (string)
kttnTimer returns a KttnTimer.
kttnEndTimer is the function returned on timer.end
.
This ends the timer and logs a message with the time result.
timer.end();
kttnEndTimer returns a number, the milliseconds it took between the start of the timer and the end. This value is also logged.
- showInitializedMessage - Should an "initialized" message be shown? (bool) (default: true)
- timestampedLog - Should a timestamp be shown in all messages? (bool) (default: true)
{
showInitializedMessage: false
}
- name - The kttn instance's name. (string)
- log - kttnLog (function)
- error - kttnError (function)
- timer - kttnTimer (function)
- timestamped - timestampedLog from newKttnInstance's options. (bool)
{
name: 'myInstance',
log: [function],
error: [function],
timer: [function],
timestamped: true
}
- timerName - The name of the timer instance. (string)
- startTime - The UNIX timestamp of the start time of the timer. (number)
- end - kttnEndTimer (function)
- log - kttnLog (function)
- timestamped - timestampedLog from newKttnInstance's options. (bool)
- name - The name of the kttn instance. (string)
{
timerName: 'myTimer',
startTime: 1524411709,
end: [function],
log: [function],
timestamped: true,
name: 'myInstance'
}