scarlet-winston
Scarlet plugin for using Winston with method and property event interception
Install
npm install scarlet-winston
Start logging
var Scarlet = ;var scarlet = '../lib/scarlet-winston';var scarletWinston = scarletpluginswinston; //Attach Logger to objectscarletWinston; //Now use intercepted object with logging!Math;//->info: [Mon Sep 02 2013 00:49:58 GMT+0100 (BST)] calling - Object::min(1,2,3)//->info: [Mon Sep 02 2013 00:49:58 GMT+0100 (BST)] Object::min(1,2,3) - returned:1 - execution time(0:0:0.0)
Getting Started
This plugin requires Scarlet ~2.0.x
If you haven't used Scarlet before, be sure to check out the Documentation. To use this plugin perform the following:
Install scarlet
npm install scarlet --save
Install plugin
npm install scarlet-winston --save
Once the plugin has been installed, you can use it in your application as follows:
//load scarletvar Scarlet = ; //Initialize scarlet with the pluginvar scarlet = 'scarlet-winston';var scarletWinston = scarletpluginswinston;
Motvation
Scarlet-Winston was created to allow applications to get the benefits of event based interception using scarlet and robust full featured logging using winston.
Scarlets event based interception is asynchronous and gets events on methods/properties before, after, and on error. Scarlet-Winston listens for these events and logs them.
How do I Configure Winston?
You can easily override the default winston implementation by passing the custom configured winston logger to scarlet-winston as follows:
scarletWinston;
Also, scarletWinston extends winston so has all its methods, in addition you can access winston as follows:
scarletWinstonwinston
For more information on how to configure winston please go here.
Custom messages during the before and after events.
If you want to customize the before and after event logs do the following:
scarletWinston{ scarletWinston;}; scarletWinston{ scarletWinston;};
Examples
Start logging for an instance
var Scarlet = ;var scarlet = 'scarlet-winston';var scarletWinston = scarletpluginswinston; //Define a function to log{ this{ console; }};var functionToLogInstance = ; //Attach Logger to objectscarletWinston; //Now use intercepted object with logging!functionToLogInstance;//->info: [Tue Aug 27 2013 23:51:16 GMT+0100 (BST)]calling - FunctionToLog::logMe()//->In logMe//->info: [Tue Aug 27 2013 23:51:16 GMT+0100 (BST)]FunctionToLog::logMe() - returned:undefined - execution time(0:0:0.1)
Start logging for an instance with custom winston configuration
var Scarlet = ;var scarlet = 'scarlet-winston';var scarletWinston = scarletpluginswinston; //Define a function to log{ this{ console; }};var functionToLogInstance = ; //Create a custom winston configurationvar logger = new winstonLogger transports: new winstontransportsConsole new winstontransportsFile filename: 'somefile.log' ; //Attach Logger to objectscarletWinston; //Now use intercepted object with logging!functionToLogInstance;//->info: [Tue Aug 27 2013 23:51:16 GMT+0100 (BST)]calling - FunctionToLog::logMe()//->In logMe//->info: [Tue Aug 27 2013 23:51:16 GMT+0100 (BST)]FunctionToLog::logMe() - returned:undefined - execution time(0:0:0.1)
Start logging an instances member
var Scarlet = ;var scarlet = 'scarlet-winston';var scarletWinston = scarletpluginswinston; //Define a function to log{ this{ console; } this{ console; }};var functionToLogInstance = ; //Attach Logger to objectscarletWinston; //Call a non intercepted methodfunctionToLogInstance;//-> no output //Now use intercepted object with logging!functionToLogInstance;//->info: [Tue Aug 27 2013 23:51:16 GMT+0100 (BST)]calling - FunctionToLog::logMe()//->In logMe//->info: [Tue Aug 27 2013 23:51:16 GMT+0100 (BST)]FunctionToLog::logMe() - returned:undefined - execution time(0:0:0.1)
Start logging all instances of a function
var Scarlet = ;var scarlet = 'scarlet-winston';var scarletWinston = scarletpluginswinston; { this{ console; }}; //Attach Logger to objectFunctionToLog = scarletWinston; //Now use intercepted object with logging!var functionToLogInstance = ;//-> Outputs the following to the console://->info: [Tue Aug 27 2013 09:39:55 GMT+0100 (BST)] - calling - FunctionToLog::FunctionToLog()//->info: [Tue Aug 27 2013 09:39:55 GMT+0100 (BST)] - FunctionToLog::FunctionToLog() - returned:undefined - execution time(0:0:0.0) functionToLogInstance;//-> Outputs the following to the console://->[Tue Aug 27 2013 09:39:55 GMT+0100 (BST)] - Debug - calling - FunctionToLog::logMe()//->In logMe//->[Tue Aug 27 2013 09:39:55 GMT+0100 (BST)] - Debug - FunctionToLog::logMe() - returned:undefined - execution time(0:0:0.0)
Start logging all instances of a prototype function
var Scarlet = ;var scarlet = 'scarlet-winston';var scarletWinston = scarletpluginswinston; //Define a prototype object to logvar {};ObjectToLogprototype{ console; }; //Attach Logger to objectObjectToLog = scarletWinston; //Now use intercepted object var objectToLog = ;//-> Outputs the following to the console://->[Tue Aug 27 2013 09:50:23 GMT+0100 (BST)] - Debug - calling - FunctionToLog::FunctionToLog()//-?[Tue Aug 27 2013 09:50:23 GMT+0100 (BST)] - Debug - FunctionToLog::FunctionToLog() - returned:undefined - execution time(0:0:0.1) //When called will now get loggedvar result = objectToLog;//-> Outputs the following to the console://->[Tue Aug 27 2013 09:50:23 GMT+0100 (BST)] - Debug - calling - FunctionToLog::logMe()//->In logMe//->[Tue Aug 27 2013 09:50:23 GMT+0100 (BST)] - Debug - FunctionToLog::logMe() - returned:undefined - execution time(0:0:0.0)