min-log
Better Logger with Custom Level and Outputer Taking over the original console
Support All Browsers which can Display on page or in Console, for Phone and old IE debugging, support wechat miniprogram
Installation
npm i min-log
Usage
var log = log
Direct Replace console
If you already has a project with console.log
, just add a plugin to webpack config
then min-log
will take over all consoles and hide all logs by default
plugins: console: 'min-log'
If want have logger with namespace
e.g. animal.js
, use filename as log namespace to take over console
const console =
Advanced Usage
debug with namespace like package name
var log = log
Run Debug Code Block
var log = if log
Log History
min-log
default enable history, default history size is 3000
Api | Description |
---|---|
log.setHistorySize(1000) |
Set history size |
log.disableHistory() |
Disable history |
log.getHistory() |
Get history |
log.clear() |
Clear history |
log.save() |
Save history |
Debug Level
Set Level
log // set debug level
Level | Description |
---|---|
verbose |
Detail and verbose debug log only developper cares |
debug |
Debug log only developper cares |
info |
Normal info user should care like login or logout |
warn |
Some waring user should care like cookie expired |
error |
Some serious error user should care like server return error |
fatal |
Some fatal error which will crash the program |
Outputer
Set Outputer
log // set browser color outputer
Outputer | Usage |
---|---|
console |
Simple console output like console.log |
node_console |
Print log with color in node |
browser_console |
Print log with color in browser |
browser_html |
Print log in document by html (for old IE or phone website) |
vconsole |
Remote call vConsole to print log |
eruda |
Remote call Eruda to print log |
Debug Style
If you like tj@debug and just use debug
level, you can do this
var debug = 'http'
Set Config
You can set log config for min-log
Name | Purpose |
---|---|
log_name |
Enables/disables specific debugging namespaces |
log_level |
Set log level like debug |
log_outputer |
Set outputer like browser_html |
min-log
will try to get user config from three ways in order
Query
in page url e.g.my.site.com/path?log_name=*&log_level=debug&log_output=browser_html
localStorage
e.g.localStorage.log_level = debug
Environment
e.g.log_level=debug log_name=main* node app.js
Other Config
set log colors
log
set log namespace prefix
log
Formatter
TODO
Formatter | Representation |
---|---|
%O |
Pretty-print an Object on multiple lines |
%o |
Pretty-print an Object all on a single line |
%s |
String |
%d |
Number |
%j |
JSON |
%% |
Single percent sign ('%'). This does not consume an argument |