Skip to content
Simple JavaScript console-logger
JavaScript HTML
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
__mocks__
__tests__
scripts
src
.babelrc
.eslintrc.json
.flowconfig
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
package-lock.json
package.json
rollup.config.js
sample.html

README.md

js-simple-logger

Build Status npm version

Simple JavaScript console logger.

Table of contents

Installation

npm install --save js-simple-logger

Usage

Simple logger

import * as Logger from 'js-simple-logger';

const logger = Logger.getLogger();
logger.trace('message');
logger.debug('message');
logger.table([1, 2, 3]);
logger.info('message');
logger.log('message');
logger.warn('message');
logger.error('message');

Contextual logger

import * as Logger from 'js-simple-logger';

const logger = Logger.getLogger('myFunc');
logger.debug('message');

setDateFormat

Use this function before creating any loggers:

import * as Logger from 'js-simple-logger';

Logger.setDateFormat('mm:ss');

setMinimumLogLevel

Use this function before creating any loggers:

import * as Logger from 'js-simple-logger';

Logger.setMinimumLogLevel(Logger.getLogLevels().TRACE);

Available log levels:

  • OFF (-1)
  • TRACE (0)
  • DEBUG (1)
  • TABLE (2)
  • INFO (3)
  • LOG (4)
  • WARN (5)
  • ERROR (6)

setFormatter

Use this function before creating any loggers:

import * as Logger from 'js-simple-logger';

Logger.setFormatter((metaInformation = {}) => (messages) => {
  const {dateFormat, logLevel, context} = metaInformation;
  
  return [Logger.formatLogLevel(logLevel), context].concat(messages);
});

Breaking changes

1.x.x > 2.x.x

Instead of new Logger() you create a new logger by using getLogger().

License

MIT (https://github.com/Kaishiyoku/js-simple-logger/blob/master/LICENSE)

Author

Twitter: @kaishiyoku
Website: www.andreas-wiedel.de

/

You can’t perform that action at this time.