# @littlethings/log

> A simple logging utility.

Latest version **3.0.9** (published 2024-08-28) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @littlethings/log
pnpm add @littlethings/log
yarn add @littlethings/log
bun add @littlethings/log
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.9 |
| Published | 2024-08-28 |
| First published | 2020-05-12 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 34.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Jake Hamilton |
| Maintainers | jakehamilton |

## Links

- npm: https://www.npmjs.com/package/@littlethings/log
- Repository: https://github.com/jakehamilton/littlethings
- Issues: https://github.com/jakehamilton/littlethings/issues
- npm.io page: https://npm.io/package/@littlethings/log

## Dependencies (1)

- [kleur](https://npm.io/package/kleur.md) ^4.1.3

## Recent versions

- 3.0.9 (latest) — 2024-08-28
- 3.0.8 — 2024-02-29
- 3.0.7 — 2023-12-23
- 3.0.6 — 2022-12-06
- 3.0.5 — 2022-05-01
- 3.0.4 — 2022-05-01
- 3.0.3 — 2022-04-30
- 3.0.2 — 2022-04-20
- 3.0.1 — 2022-04-14
- 3.0.0 — 2022-04-14
- 2.6.1 — 2022-04-10
- 2.6.0 — 2022-01-24
- 2.5.0 — 2021-03-23
- 2.4.2 — 2021-03-23
- 2.4.1 — 2021-02-28
- … 21 more at https://npm.io/package/@littlethings/log/versions

## README

<p align="center">
  <img src="https://raw.githubusercontent.com/jakehamilton/littlethings/main/packages/log/assets/littlelog.png" width="400">
</p>

# LittleLog

> A simple logging utility.

## Preview

<img src="https://raw.githubusercontent.com/jakehamilton/littlethings/main/packages/log/assets/preview.png">

## Installation

Install using your favorite package manager:

```bash
npm install @littlethings/log
```

## Usage

### Configuration

#### Programmatic

To configure LittleLog using the `configure` function, see the following example.#

```ts
import { configure, LogLevel } from "littlelog";

configure({
	/**
	 * How verbose the logging should be.
	 * Defaults to `process.env.LOG_LEVEL`.
	 */
	level: LogLevel.Info,
	/**
	 * An optional filter used to filter logs based on prefix.
	 * Defaults to `undefined`.
	 */
	filter: "my-prefix",
	/**
	 * Whether or not to log prefixes before messages.
	 * Defaults to `true`.
	 */
	prefix: false,
	/**
	 * Whether or not to log timestamps.
	 * Defaults to `true`.
	 */
	timestamp: false,
	/**
	 * Whether or not to enable color logging.
	 * Defaults to `true` if in a TTY, otherwise defaults to `false`.
	 */
	color: false,
	/**
	 * Whether or not to enable icons in logs.
	 * Defaults to `false`.
	 */
	icons: true,
});
```

#### Environment Variables

Default values can be supplied via the environment, but they may be
overriden by programmatic configuration as seen above.

```shell
# Set the log level (options are: SILENT, INFO, DEBUG, TRACE).
LOG_LEVEL=INFO

# Don't log prefixes.
LOG_PREFIX=false

# Enable timestamps.
LOG_TIMESTAMP=true

# Filter logs based on prefix regex.
LOG_FILTER="^my-app$"
# You can use the more common `DEBUG` variable for filtering if you prefer.
#DEBUG="^my-app$"

# Enable color.
LOG_COLOR=true

# Disable color.
LOG_COLOR=false

# Or, for compatibility with Chalk, you can use `FORCE_COLOR`.
FORCE_COLOR=1
FORCE_COLOR=0

# Enable icons.
LOG_ICONS=true
```

### Logging

To log messages using the base logger, see the following example.

```ts
import log from "littlelog";

log.info("This is an info log.");

log.debug("This is a debug log.");

log.trace("This is a trace log.");

log.warn("This is a warn log.");

log.error("This is an error log.");

log.fatal("This is a fatal log.");
```

To create a child logger with a unique prefix, see the following example.

```ts
import littlelog from "littlelog";

// This will have the prefix `MyLogger`.
const myLogger = littlelog.child("MyLogger");

myLogger.info("This is an info log.");

myLogger.debug("This is a debug log.");

myLogger.trace("This is a trace log.");

myLogger.warn("This is a warn log.");

myLogger.error("This is an error log.");

myLogger.fatal("This is a fatal log.");

// You can continue to create child loggers if you want!
// This will have the prefix `MyLogger:MySubLogger`.
const mySubLogger = littlelog.child("MySubLogger");

mySubLogger.info("This is an info log.");

mySubLogger.debug("This is a debug log.");

mySubLogger.trace("This is a trace log.");

mySubLogger.warn("This is a warn log.");

mySubLogger.error("This is an error log.");

mySubLogger.fatal("This is a fatal log.");
```

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