# consolite

> Light wrapper for console

Latest version **0.3.12** (published 2023-07-21) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 30/100 (F)** — status: abandoned.

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.12 |
| Published | 2023-07-21 |
| First published | 2021-09-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 104.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | jakobrosenberg@gmail.com |
| Maintainers | jakobrosenberg |
| Keywords | log, logging, debug, console, print |

## Links

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

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

- 0.3.12 (latest) — 2023-07-21
- 0.3.11 — 2023-01-06
- 0.3.10 — 2022-07-01
- 0.3.9 — 2022-07-01
- 0.3.8 — 2022-04-11
- 0.3.7 — 2022-04-11
- 0.3.6 — 2022-03-31
- 0.3.5 — 2022-03-29
- 0.3.4 — 2022-03-29
- 0.3.3 — 2022-02-10
- 0.3.2 — 2022-02-10
- 0.3.1 — 2022-02-10
- 0.3.0 — 2022-02-09
- 0.2.10 — 2022-01-07
- 0.2.9 — 2021-11-04
- … 13 more at https://npm.io/package/consolite/versions

## README

<img src="./consolite.svg" style="width:100%">

## Features
- **It's tiny** - 371 bytes gzip + minify.
- **It preserves line numbers** - so you can find exactly where your code was logged.
- **Prefixing** - provide context for your logs by adding a prefix.
- **Nesting** - sometimes you need to add extra context. This can be handled by creating a child logger
- **Log levels** - log levels can be customized and are inherited by child instances
- **Native console methods** - consolite wraps around `console` so any method available on console will be available on consolite.

## Install
```
npm install consolite
```

## Basic Usage
```javascript
import { createLogger } from 'consolite'

const log = createLog()

log.log('hello world') // prints "hello world"
```


## Examples

### Using prefix
```javascript
const log = createLog('[my-prefix]')

log.log('hello world') // prints "[my-prefix] hello world"
```
### Using a function prefix
```javascript
const log = createLog(method => `${method} ->`)
log.debug('hello world') // prints "debug -> hello world"
```


### Child logger
Child loggers inherit prefixes, levels and level from their parents.
```javascript
const log = createLog('[parent]')
const childLog = log.createChild('[child]')

log.log('hello world') // prints "[parent] [child] hello world"
```

### Changing log level
```javascript
const log = createLog()

log.debug('hello world') // does nothing
log.level = 4 // 3 by default
log.debug('hello world') // prints "hello world"

```

### Changing default levels
```javascript
const log = createLog()

log.debug('hello world') // does nothing
log.levels.debug = 3 // set debug to match current logging level
log.debug('hello world') // prints "hello world"
```

### Adding custom method
```javascript
const log = createLog()
log.register('silly', console.log)
log.levels.silly = 8
log.silly('hello world')
```

### Filtering messages
```javascript
const log = createLog()
log.filter = (prefixes, method) => method !== 'debug' || process.env.DEBUG
```

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