2.6.1 • Published 6 years ago

min-log v2.6.1

Weekly downloads
241
License
ISC
Repository
-
Last release
6 years ago

min-log

browser_console

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

Example page

Installation

npm i min-log

Usage

var log = require('min-log')

log.debug('hello')

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: [
  new webpack.ProvidePlugin({
    console: 'min-log'
  })
]

If want have logger with namespace

e.g. animal.js, use filename as log namespace to take over console

const console = require('min-log').getLogger('animal')

Advanced Usage

debug with namespace like package name

var log = require('min-log').getLogger('com:foo')

log.debug('this file log')

Run Debug Code Block

var log = require('min-log')
if (log.isDebugEnabled()) {
  doSomeMockThing()
}

Log History

min-log default enable history, default history size is 3000

ApiDescription
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.setLevel('debug') // set debug level
LevelDescription
verboseDetail and verbose debug log only developper cares
debugDebug log only developper cares
infoNormal info user should care like login or logout
warnSome waring user should care like cookie expired
errorSome serious error user should care like server return error
fatalSome fatal error which will crash the program

Outputer

Set Outputer

log.setOutputer('browser_color') // set browser color outputer
OutputerUsage
consoleSimple console output like console.log
node_consolePrint log with color in node
browser_consolePrint log with color in browser
browser_htmlPrint log in document by html (for old IE or phone website)
vconsoleRemote call vConsole to print log
erudaRemote call Eruda to print log

Debug Style

If you like tj@debug and just use debug level, you can do this

var debug = require('min-log/debug')('http')

debug('booting')

Set Config

You can set log config for min-log

NamePurpose
log_nameEnables/disables specific debugging namespaces
log_levelSet log level like debug
log_outputerSet outputer like browser_html

min-log will try to get user config from three ways in order

  1. Query in page url e.g. my.site.com/path?log_name=*&log_level=debug&log_output=browser_html
  2. localStorage e.g. localStorage.log_level = debug
  3. Environment e.g. log_level=debug log_name=main* node app.js

Other Config

set log colors

log.setColors(['#f8f8f2', 'goldenrod', '#66d9ef', '#a6e22e', '#e6db74', '#f92672'])

set log namespace prefix

log.setPrefix('com:company:')

Formatter

TODO

FormatterRepresentation
%OPretty-print an Object on multiple lines
%oPretty-print an Object all on a single line
%sString
%dNumber
%jJSON
%%Single percent sign ('%'). This does not consume an argument
2.6.1

6 years ago

2.6.0

6 years ago

2.5.0

6 years ago

2.3.0

6 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.11.0

7 years ago

1.10.0

7 years ago

1.9.0

7 years ago

1.8.0

7 years ago

1.7.0

7 years ago

1.6.0

8 years ago

1.5.0

8 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.0.1

8 years ago