captains-log-nw
The lightweight logger from SailsJS now made ready for NW. Optional support for colorized output, custom prefixes and log levels (using npm's logging conventions).
Installation
$ npm install captains-log-nw
Usage
var log = ;;
See also Console API.
Logging at a particular level
By default, if you just call log()
, captains-log-nw will write your log output at the "debug" log level. You can achieve the same effect by writing log.debug()
.
IMPORTANT NOTE: npm calls this level
log.http()
, but we call itdebug
. If you uselog()
, the logger sees this as a call tolog.debug()
)
Here are all of the log-level-specific methods which are available in captains-log-nw out of the box:
var log = level: 'silly'; log;log;log;log; // will output white text on a white background.log;log;log;log; // same as error, but can be configured to be different in style. // using other features from console, which will only be applied in silly log level// (and have the same colors applied)logsilly;log;logsilly;
Setting level: 'silent'
will disable all logging, while setting level: 'silly'
will enable all levels of logging. For more details information, see SailsJS logging.
Configuration
For node-webkit, it's easiest if the globalizeAs
option is used to expose the logger throughout the application.
var CaptainsLog = ; var log = level: 'debug' globalizeAs: 'log' // make it available globally, without using require() console: console // passing in the console from the Window object (Browser context) // makes the logs visible in the Developer Tools. prefixTheme: 'aligned' // Use a different prefix for string logs. colors: false // disable colors altogether.;
It's possible to set the prefixes manually as well as changing the color of the output for specific levels.
var CaptainsLog = ; var log = level: 'verbose' prefixes: silly : 'silly : ' verbose : 'verbose: ' info : 'info : ' blank : '' debug : '' warn : '' error : '' crit : '' prefixTheme: 'moderate' // will be ignored, since prefixes are set manually. colors: // NW's console allows for css styling for log output crit: 'color: red; font-weight: 600; font-size: 18px; text-transform: uppercase' ;
Configuring a custom logger
Not Tested
To use a different library, overrides.custom
must already be instantiated and ready to go with (at minimum) an n-ary .debug()
method.
Implementing the simplest possible override
var log = custom: customLogger ; ;// yields => "Hello world"
This assumes customLogger
works as follows:
customLoggercustomLoggercustomLoggercustomLoggercustomLogger;// etc.
For example:
var customLogger = consolelog;
Using Winston
Formerly, this module encapsulated winston, a popular logger by @indexzero and the gals/guys over at Nodejitsu. Recently, we made Winston optional to make captains-log as lightweight as possible and reduce the number of npm install
s and require()
s necessary for its usage in other modules.
But Winston is awesome! And it's a great fit for many apps, giving you granular control over how log output is handled, including sending emails, logging to multiple transports, and other production-time concerns.
To use boot up a captains-log that writes to Winston, do the following:
var log = custom: new Logger levels : ... transports : ... ;
License
MIT