bconsole - A better console for node.js
bconsole extends node.js's built in console
with several additions:
- Line number
- Colorized! (togglable)
- Warnings and Errors
- Object logging (using util.inspect())
- Groups
- Toggle groups of logs/errors/warnings on or off dynamically
- Truncate long group names when not enough room in prefix
- Keeps start of all messages aligned on the same column
- Options customizeable on the fly!
Installation
Run
npm install bconsole
and then add
var bconsole = /* options */
to your project.
Example
The following output:
Is a result of the following code:
1 | // instantiate with custom options2 | var bconsole = 3 | pad_to: 184 | ;5 | 6 | // Classic log/warn/error7 | bconsole;8 | bconsole;9 | bconsole;10 | 11 | // Supports groups12 | bconsole;13 | 14 | bconsole;15 | bconsole;16 | bconsole;17 | 18 | bconsole;19 | 20 | bconsole;21 | 22 | // Groups can be strings too23 | bconsole;24 | 25 | bconsole;26 | bconsole;27 | bconsole;28 | 29 | // Logs objects using util.inspect()30 | bconsole;34 | 35 | // Supports multiline logs!36 | bconsole37 | 38 | // Groups with long names are truncated if there is not39 | // enough room in the prefix40 | bconsole;41 | bconsole;42 | 43 | bconsole;46 | 47 | // Toggle color on or off48 | bconsole;49 | bconsole;50 | bconsole;51 | 52 | bconsole;53 | 54 | // Change options on the fly!55 | bconsole;56 | for var i = 20; i >= 10; i-- 57 | bconsole;58 | bconsole;59 | ... 138 | bconsole139 | bconsole
Methods
/* --------------- * * Logging Methods * * --------------- */ // Unconditional logging, will always firebconsole bconsole bconsole // Group based logging, will only fire if associated group is enabledbconsole bconsole bconsole /* -------------- * * Option Methods * * -------------- */ bconsole // Set group "group_name" to true / false // If no state is given, will flip state of groupbconsole // Change option to desired setting
Default Options
To override these options, when instantiating bconsole, pass is an object with any modified properties. To change properties after instantiation, use bconsole.setOption
.
pad_to: 16 /* int */ // The number of chars before " | " color: true /* bool */ // Enable ANSI Color codes in output groups: /* obj */ // Enable / Disable multiple groups at instantiation "testgroup": true /* bool */ ...
NOTE: groups
is a special option that can only be passed in at instantiation! To change enabled groups after the fact, use bconsole.toggleGroup()
Changelog
1.0.1
- Added option to output all logs to
stderr
1.0.0
- Initial Release