# logua

> Logging utility for node.

Latest version **3.0.3** (published 2023-12-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install logua
pnpm add logua
yarn add logua
bun add logua
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.3 |
| Published | 2023-12-08 |
| First published | 2020-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 18 |
| Dependencies | 1 |
| Unpacked size | 12.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Maintainers | tobua |
| Keywords | log, node, browser, logging, color |

## Links

- npm: https://www.npmjs.com/package/logua
- Repository: https://github.com/tobua/logua
- Homepage: https://github.com/tobua/logua#readme
- Issues: https://github.com/tobua/logua/issues
- npm.io page: https://npm.io/package/logua

## Dependencies (1)

- [debounce](https://npm.io/package/debounce.md) ^2.0.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 3.0.3 (latest) — 2023-12-08
- 3.0.2 — 2023-10-07
- 3.0.1 — 2023-10-07
- 3.0.0 — 2023-10-07
- 2.3.0 — 2023-07-01
- 2.2.0 — 2023-01-22
- 2.1.4 — 2021-03-13
- 2.1.3 — 2021-02-09
- 2.1.2 — 2020-11-12
- 2.1.1 — 2020-09-16
- 2.1.0 — 2020-09-16
- 2.0.1 — 2020-09-15
- 2.0.0 — 2020-09-05
- 1.0.7 — 2020-09-01
- 1.0.6 — 2020-09-01
- … 5 more at https://npm.io/package/logua/versions

## README

<p align="center">
  <img src="https://github.com/tobua/logua/raw/main/logo.png" alt="logua" width="300">
</p>

# 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.

```js
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

```js
// log.js

import { create } from 'logua'

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

Then import the contextualized log:

```js
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.

```js
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.

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

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

---
_Source: https://npm.io/package/logua · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
