exlog

1.2.0 • Public • Published

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

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

Examples

exlog.time('To time');

Returns void

timeEnd

Parameters

Examples

exlog.timeEnd('To time');

Returns void

timeStamp

Parameters

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

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

Examples

exlog.setStylesForTag('theTag', 'theStyle');

Returns void

getStylesForTag

Return the style name associated with a tag if any

Parameters

  • name string The tag name
  • defaultValue [?string] Value to return if this tag have no styles (optional, default null)

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

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

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

Examples

exlog.profile('Profile 1');

Returns void

profileEnd

Examples

exlog.profile();

Returns void

time

Parameters

Examples

exlog.time('To time');

Returns void

timeEnd

Parameters

Examples

exlog.timeEnd('To time');

Returns void

timeStamp

Parameters

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

Returns voir

messagePartToPart

Convert a MessagePart instance to a string

Parameters

  • messagePart MessagePart
  • exlog Console

Returns string

intOr

Convert value to number or return defaultValue

Parameters

Returns number

valueOr

Return value if not null, else return defaultValue

Parameters

  • value ?string
  • defaultValue [string] (optional, default '')

Returns string

parseLine

Parse a line of stack

Parameters

Returns ?Object

isImportant

Is the line important

Parameters

Returns boolean

parse

Parse a stack

Parameters

  • stack string The stack to parse
  • options Object Options
  • callback function Callback to call for each line

Returns Array<Any>

getStyleName

Get style name

Parameters

Returns string

transformerCallback

Parameters

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

Color

Allowed colors:

  • black
  • blue
  • cyan
  • gray
  • green
  • magenta
  • red
  • white
  • yellow

Readme

Keywords

none

Package Sidebar

Install

npm i exlog

Weekly Downloads

1

Version

1.2.0

License

BSD-3-Clause

Last publish

Collaborators

  • expeek