exlog v1.2.0
Exlog
Generate and open documentation
npm run open-docAPI
exlog
Exlog is based on Chrome DevTools API
It support browser console, terminal console and v8_inspector console
Exlog is an uniq instance of Console
Exlog is defined with default styles:
- default
- error
- error-column
- error-default
- error-line
- error-location
- error-method
- error-unimportant
- group-padding
- info
- level
- log
- tag
- warn
Examples
import exlog from 'exlog';
exlog.log('blah blah');Console
debug
Parameters
args...Any
Examples
exlog.debug('text to debug');Returns void
error
Parameters
args...Any
Examples
exlog.error(new Error());Returns void
group
Parameters
args...Any
Examples
exlog.group('A group');Returns void
groupCollapsed
Parameters
args...Any
Examples
exlog.groupCollapsed('A collapsed group');Returns void
groupEnd
Examples
exlog.groupEnd();Returns void
info
Parameters
args...Any
Examples
exlog.info('Text to log');Returns void
log
Parameters
args...Any
Examples
exlog.log('Text to log');Returns void
profile
Parameters
labelstring
Examples
exlog.profile('Profile 1');Returns void
profileEnd
Examples
exlog.profile();Returns void
trace
Parameters
args...Any
Examples
exlog.trace('A trace');Returns void
time
Parameters
labelstring
Examples
exlog.time('To time');Returns void
timeEnd
Parameters
labelstring
Examples
exlog.timeEnd('To time');Returns void
timeStamp
Parameters
labelstring
Examples
exlog.timeStamp('To time');Returns void
warn
Parameters
args...Any
Examples
exlog.warn('A warning !');Returns void
s
Apply registered style styleName to text
Parameters
Examples
let s = exlog.s;
// Configure a style
exlog.setStyles('theStyle', {
color: 'red',
});
exlog.warn(s('the text', 'theStyle'));Returns MessagePart
logUncaughtExceptions
Log uncaught exceptions
Returns void
logUnhandledRejections
Log unhandled rejection in promises
Returns void
logWarnings
Log warnings from nodejs
Returns void
isTTY
Is TTY ?
Returns boolean
isBrowser
Is in browser environment ?
Returns boolean
isTerminal
Is in terminal environment ?
Returns boolean
persistent
Get a persistent thing. At the moment, only one thing is handled : tag
Parameters
Examples
let tags = exlog.persistent('tag');Returns Any
persistent
Set persistent thing. At the moment, only one thing is handled : tag
Parameters
Examples
exlog.persistent('tag', 'tag-1', 'tag-2', 'tag-3');Returns Any
addTransformer
Add a transformer that will be called for each Message
Parameters
callbacktransformerCallback
Returns Console
setStyles
Set a style to reuse it with tag or message
Parameters
Examples
exlog.setStyles('theStyle', {
color : 'red',
bgColor : 'blue',
bold : true,
underline: false,
reset : false,
});Returns void
getStyles
Get a style to reuse it with tag or message
Parameters
Examples
let styles = exlog.getStyles('theStyle');Returns void
setStylesForTag
Associate a style to a tag
Parameters
namestring The tag namestyleNamestring The style name registered with #setStyles
Examples
exlog.setStylesForTag('theTag', 'theStyle');Returns void
getStylesForTag
Return the style name associated with a tag if any
Parameters
namestring The tag namedefaultValue[?string] Value to return if this tag have no styles (optional, defaultnull)
Examples
let styleName = exlog.getStylesForTag('theTag');Returns ?string
withoutTransformers
Return a new Message instance with transformers ignored
Examples
exlog.withoutTransformers().log('Message to log without transformers');Returns Message
tag
Return a new Message with one or many tags
Parameters
args...Any
Examples
exlog.tag('tag-1', 'tag-2').warn(`It's a warning with tags tag-1 and tag-2`);Returns Message
assert
Writes a message to the console if the assertion is false. If the assertion is true, nothing happens.
Parameters
expressionbooleanargs...Any
Examples
exlog.assert(typeof window !== 'undefined', 'window is not defined');Returns void
clear
Clear the console if possible
Examples
exlog.clear();Returns void
count
Display a message and how many times it was called
Parameters
args...Any
Returns void
dir
Inspect any variable
Parameters
objObject The object to inspect
Examples
exlog.dir(exlog);Returns void
on
on
on
Message
console
assert
Writes a message to the console if the assertion is false. If the assertion is true, nothing happens.
Parameters
expressionbooleanargs...Any
Examples
exlog.assert(typeof window !== 'undefined', 'window is not defined')Returns void
clear
Clear the console if possible
Examples
exlog.clear();Returns void
count
Display a message and how many times it was called
Parameters
args...Any
Returns void
debug
Parameters
args...Any
Examples
exlog.debug('text to debug');Returns void
error
Parameters
args...Any
Examples
exlog.error(new Error());Returns void
group
Parameters
args...Any
Examples
exlog.group('A group');Returns void
groupCollapsed
Parameters
args...Any
Examples
exlog.groupCollapsed('A collapsed group');Returns void
groupEnd
Examples
exlog.groupEnd();Returns void
info
Parameters
args...Any
Examples
exlog.info('Text to log');Returns void
log
Parameters
args...Any
Examples
exlog.log('Text to log');Returns void
profile
Parameters
labelstring
Examples
exlog.profile('Profile 1');Returns void
profileEnd
Examples
exlog.profile();Returns void
time
Parameters
labelstring
Examples
exlog.time('To time');Returns void
timeEnd
Parameters
labelstring
Examples
exlog.timeEnd('To time');Returns void
timeStamp
Parameters
labelstring
Examples
exlog.timeStamp('To time');Returns void
trace
Parameters
args...Any
Examples
exlog.trace('A trace');Returns void
warn
Parameters
args...Any
Examples
exlog.warn('A warning !');Returns void
push
Push a part
Parameters
partAnystyleNamestring
Returns voir
messagePartToPart
Convert a MessagePart instance to a string
Parameters
messagePartMessagePartexlogConsole
Returns string
intOr
Convert value to number or return defaultValue
Parameters
Returns number
valueOr
Return value if not null, else return defaultValue
Parameters
Returns string
parseLine
Parse a line of stack
Parameters
linestring
Returns ?Object
isImportant
Is the line important
Parameters
lineObject
Returns boolean
parse
Parse a stack
Parameters
stackstring The stack to parseoptionsObject Optionscallbackfunction Callback to call for each line
Returns Array<Any>
getStyleName
Get style name
Parameters
styleNamestring
Returns string
transformerCallback
Parameters
messageMessage The original message to transformsfunction The #Console#s methodconsoleConsole The console instance
Returns ?Message Must return nothing or the original message mutated
Styles
By default, styles is set like that:
{
paddingLeft : 1,
paddingRight: 1,
reset : true,
}Properties
boldbooleancapitalizebooleanlowerCasebooleanreset[boolean]underlinebooleanupperCasebooleanbgColorColor Background colorcolorColor Text colorpaddingLeft[number]paddingRight[number]
Color
Allowed colors:
- black
- blue
- cyan
- gray
- green
- magenta
- red
- white
- yellow