Fancy lightweight logging utility for Node.js
Installation
Prerequisites: Node.js 6+, npm 3+.
npm install --save hiplog
Usage
const Log = ;const log = level: 'debug' ;
log;log;log;log;log;log;log;log;
Objects
Objects are automatically stringified using Purdy. Small objects (< 200 characters) are inlined.
log;
const circular = {};circularinner = circular; log;
Errors
Errors are displayed using jest-message-util:
try throw 'Error example'; catch e log;
Options
level
- type:
string
- default value:
'info'
Minimum level to display. All messages below this level will be ignored.
stream
- type:
Steam | function: integer -> Stream
- default value:level <= 4 ? processstderr : processstdout
Stream to write to.
displayTime
- type:
boolean
- default value:
false
Whether to display time information or not. Example:
displayTimeFormat
- type:
string
- default value:
'yyyy-mm-dd HH:MM:ss.l'
Date format to display time in, when displayTime
is set to true
. See dateformat
for possible values.
separator
- type:
string
- default value:
' • '
Separator between message header and body, and also between time and and label,
when displayTime
is set to true
;
format
- type:
function: string -> string
- default value:
hiplog.format
Message formatter function.
fromEnv
const hiplog = ;const log = hiplog;
fromEnv
is a utility function that will create a new instance of Log
with
options taken from environment variables:
NODE_ENV
:'development'
(default):displayTime
is disabled,'test'
:displayTime
is disabled,'level'
is set to'critical'
,'production'
: use default values for each option.
LOG
: setslevel
value.LOG_LEVEL
: alias forLOG
.LOG_TIME
: when set totrue
or1
, enablesdisplayTime
.LOG_TIME_FORMAT
: setsdisplayTimeFormat
value.
Note: fromEnv
accepts an options
parameter that allow overriding these defaults. Example:
const hiplog = ;const log = hiplog;// displayTime will be always `false`, disregarding the value of `LOG_TIME`.
Contributing
Please refer to the guidelines for contributing.
License
Created with npm-package-skeleton.