exlog v1.2.0
Exlog
Generate and open documentation
npm run open-doc
API
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
label
string
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
label
string
Examples
exlog.time('To time');
Returns void
timeEnd
Parameters
label
string
Examples
exlog.timeEnd('To time');
Returns void
timeStamp
Parameters
label
string
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
callback
transformerCallback
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
name
string The tag namestyleName
string 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
name
string 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
expression
booleanargs
...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
obj
Object 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
expression
booleanargs
...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
label
string
Examples
exlog.profile('Profile 1');
Returns void
profileEnd
Examples
exlog.profile();
Returns void
time
Parameters
label
string
Examples
exlog.time('To time');
Returns void
timeEnd
Parameters
label
string
Examples
exlog.timeEnd('To time');
Returns void
timeStamp
Parameters
label
string
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
part
AnystyleName
string
Returns voir
messagePartToPart
Convert a MessagePart instance to a string
Parameters
messagePart
MessagePartexlog
Console
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
line
string
Returns ?Object
isImportant
Is the line important
Parameters
line
Object
Returns boolean
parse
Parse a stack
Parameters
stack
string The stack to parseoptions
Object Optionscallback
function Callback to call for each line
Returns Array<Any>
getStyleName
Get style name
Parameters
styleName
string
Returns string
transformerCallback
Parameters
message
Message The original message to transforms
function The #Console#s methodconsole
Console 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
bold
booleancapitalize
booleanlowerCase
booleanreset
[boolean]underline
booleanupperCase
booleanbgColor
Color Background colorcolor
Color Text colorpaddingLeft
[number]paddingRight
[number]
Color
Allowed colors:
- black
- blue
- cyan
- gray
- green
- magenta
- red
- white
- yellow