3.0.3 • Published 5 months ago

logua v3.0.3

Weekly downloads
57
License
MIT
Repository
github
Last release
5 months ago

logua

Logging utility for node and the browser. Displays colored package namespace in front and exits on error. Unless message ends in ".!?\n" a dot will be added to the end.

import { create } from 'logua'

// First create the log with the package context.
const log = create('my-pkg', 'blue')

log(`Found ${files} files`)

// => my-pkg Found 5 files.

log('Please add a description field', 'warning')

// => my-pkg Please add a description field.

log('package.json file is missing', 'error')

// => my-pkg package.json file is missing.
// => exits the process!

The following colors are available: black, red, green, yellow, blue, magenta, cyan, white, gray, grey, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, darkOrange, orange

Separate file

// log.js

import { create } from 'logua'

export const log = create('some-pkg', 'red')

Then import the contextualized log:

import { log } from './log.js'

log('Hello World')

// => some-pkg Hello World.

Grouping messages

To avoid spamming the log messages can be grouped. After a timeout a single message will be output instead of various messages.

const files = ['hello.js', 'world.js', 'more-files.js']

files.forEach((file) =>
  log(`Copying ${file}`, {
    // Some identifier for the group.
    group: 'copy',
    // Group message, used if there is more than one log for this id during the timeout.
    groupMessage: (count: number) => `Copying ${count} files`,
    groupMessage: 'Files copied successfully',
    // Optional timeout until messages are collected.
    timeout: 100,
  }),
)

// => Copying 3 files.

Further Options

By default a newline will be added after each message. This can be changed globally or for each single log.

const log = create('my-pkg', 'blue', false) // newLine = false

log('Hello World', { newLine: true }) // Force newLine for this message.
3.0.3

5 months ago

3.0.2

7 months ago

3.0.1

7 months ago

3.0.0

7 months ago

2.3.0

10 months ago

2.2.0

1 year ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.2

3 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago