1.3.6 • Published 6 months ago

colorogger v1.3.6

Weekly downloads
4
License
MIT
Repository
github
Last release
6 months ago

colorogger

npm downloads license GitHub top language semantic-release action-release codecov Package Quality

A simple colorful logger. Both for browser and node-server. Easy to report and record.

releases and changelog

Demo

server demo

server demo

browser demo

browser demo

Getting Started

install

npm i colorogger

server

const colorogger = require('colorogger');
const logger = new colorogger();

logger.log('log');
logger.info('info');
logger.debug('debug');
logger.warn('warn');
logger.error('error');
logger.success('success');
logger.fail('fail');
logger.tip('tip');
logger.stress('stress');

browser (with webpack)

const colorogger = require('colorogger/lib/client');
const logger = new colorogger();
logger.success('message');

Options

color

Enable colored log.

  • type: Boolean
  • default: true

timeStamp

Enable time stamp.

  • type: Boolean
  • default: true

stringify

Make log stringify and remove breaks.

  • type: Boolean
  • default: false

print

Enable logger print log to console.

  • type: Boolean
  • default: true

level

Enable logger log to console by level grade.

  • type: Number
  • default: 0

default levels grades:

  • 0: debug
  • 1: log, tip
  • 2: info, success
  • 3: warn, stress
  • 4: error

timeTemplate

Format time stamp.

  • type: String
  • default: '{{YYYY}}/{{MM}}/{{DD}} {{hh}}:{{mm}}:{{ss}}.{{mss}}'

wrapIcon

Format icon log text.

  • type: Function
  • default: (icon) => \${icon}``

wrapTag

Format meta key log text.

  • type: Function
  • default: (tag, key) => \${tag}``

meta

Extra log info.

  • type: Object
  • default: undefined

Example:

const logger = new colorogger({
  timeStamp: false,
  meta: {
    guid: 'guid_abc'
  }
});

logger.log('log text');
// console output: [.] [guid_abc] log text

transport

Resive message object.

  • type: Function
  • default: null

Example:

const logger = new colorogger({
  meta: {
    guid: 'guid_123',
  },
  transport(msg) {
    console.log(msg);
  }
});

logger.success('log text');
// msg.content: ['log text']
// msg.flag: 'success'
// msg.grade: 1
// msg.guid: 'guid_123'
// msg.level: log
// msg.time: 1599215203843

Api

config(options)

Set logger config.

  • param Object options: constructor options

Example:

const logger = new colorogger();

logger.config({
  meta: {
    guid: 'guid_123',
  },
  transport(msg) {
    console.log(msg);
  }
})

logger.log('log text');
// msg.content: ['log text']
// msg.flag: ''
// msg.grade: 1
// msg.guid: 'guid_123'
// msg.level: log
// msg.time: 1599215203843

fork(options?)

Clone instance.

  • param Object options: constructor options

Example:

const logger = new colorogger({
  meta: {
    guid: 'guid_123',
  },
  transport(msg) {
    console.log(msg);
  }
});
const forkLogger = logger.fork();

forkLogger.log('log text');
// msg.content: ['log text']
// msg.guid: 'guid_123'
forkLogger.success('success text');
// msg.content: ['success text']
// msg.guid: 'guid_123'

method(name, options?)

Extend a method for logger instance.

Example:

const logger = new colorogger({
  transport(msg) {
    console.log(msg);
  }
});

logger.method('intro', {
  level: 'info',
  flag: 'intro',
  color: '#ff9501',
});

logger.intro('intro text');
// msg.content: ['intro text']
// msg.flag: 'intro'
// msg.level: 'info'

theme(options)

Custom color setting.

  • param Object options: theme options
    • param Object options.colors: Configure the color of the method output log.
    • param Object options.icons: icon options
      • param Object options.iconsname: Configure the icon for the method output log.

Example:

const logger = new colorogger({
  transport(msg) {
    console.log(msg);
  }
});

logger.method('intro', {
  level: 'info',
  flag: 'intro',
});

logger.theme({
  colors: {
    intro: '#ff9501',
  },
  icons: {
    intro: {
      icon: 'i',
      color: '#00ff00',
    }
  }
});

logger.intro('intro text');

intro demo

destroy()

Destroy instance.

1.3.6

6 months ago

1.3.5

11 months ago

1.3.4

12 months ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.0

4 years ago