# @yingyeothon/logger

> Minimal structured logger with severity filtering, composition, and pluggable writers.

Latest version **2.2.0** (published 2026-09-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @yingyeothon/logger
pnpm add @yingyeothon/logger
yarn add @yingyeothon/logger
bun add @yingyeothon/logger
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2026-09-08 |
| First published | 2019-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 17.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | yingyeothon |
| Maintainers | lacti |
| Keywords | yyt, yingyeothon |

## Links

- npm: https://www.npmjs.com/package/@yingyeothon/logger
- Repository: https://github.com/yingyeothon/tslib
- Homepage: https://github.com/yingyeothon/tslib/tree/main/packages/logger#readme
- npm.io page: https://npm.io/package/@yingyeothon/logger

## Recent versions

- 2.2.0 (latest) — 2026-09-08
- 2.1.0 — 2026-09-08
- 2.0.2 — 2026-09-06
- 2.0.1 — 2026-08-28
- 2.0.0 — 2026-08-28
- 0.4.0 — 2023-08-23
- 0.3.1 — 2020-10-04
- 0.3.0 — 2020-10-04
- 0.2.2 — 2020-03-14
- 0.2.1 — 2019-11-24
- 0.2.0 — 2019-11-15
- 0.1.0 — 2019-07-31

## README

# @yingyeothon/logger

Minimal structured logger with severity filtering, writer composition, and pluggable log writers. Built for tiny serverless bundles: zero dependencies, a few hundred bytes of code.

One threshold, then any number of writers; an omitted `logger` option becomes `nullLogger`.

```mermaid
flowchart LR
  A["logger.info(message, context)"] --> F["createFilteredLogger<br/>severity threshold"]
  F --> C["combine"]
  C --> W1["consoleWriter"]
  C --> W2["your own LogWriter"]
  N["nullLogger"] -.->|"the default when logger is omitted"| A
```

## Install

```bash
npm install @yingyeothon/logger
```

## Usage

ESM:

```ts
import {
  combine,
  createConsoleLogger,
  createFilteredLogger,
  nullLogger,
} from "@yingyeothon/logger";

const logger = createConsoleLogger("info");
logger.debug("dropped: below severity");
logger.info("hello", { requestId: "r-1" });
logger.error("boom", new Error("bad"));

// Compose multiple writers and filter them together.
const buffered: string[] = [];
const audit = createFilteredLogger({
  severity: "debug",
  writer: combine(
    {
      debug: () => {},
      info: (...a) => buffered.push(a.join(" ")),
      warn: console.warn,
      error: console.error,
    },
    nullLogger, // combine() skips the null logger
  ),
});
audit.info("stored");
```

CJS:

```js
const { createConsoleLogger } = require("@yingyeothon/logger");
const logger = createConsoleLogger("debug");
logger.debug("visible now");
```

## Public API

- `createConsoleLogger(severity?)` — `Logger` filtering the console writer (default severity `"info"`)
- `createFilteredLogger(options)` — `Logger` that writes to `options.writer` only when the record's severity is at or above the logger's (mutable) `severity`
- `combine(...writers)` — fan-out writer; skips `nullLogger`
- `consoleWriter` — `LogWriter` backed by `console.debug/info/warn/error`
- `nullLogger` — a `Logger` that drops everything
- Types: `LogSeverity` (`"none" | "debug" | "info" | "warn" | "error"`), `LogWriter` (`{ debug, info, warn, error }` sink interface), `Logger` (`LogWriter` plus a mutable `severity` field), `FilteredLoggerOptions` (`{ severity, writer }`)

## Migrating from the legacy package

- The exported classes are gone: `new ConsoleLogger(severity)` becomes `createConsoleLogger(severity)` and `new FilteredLogger(severity, writer)` becomes `createFilteredLogger({ severity, writer })`. The returned objects are plain `Logger` values with the same behavior, including the mutable `severity` field.
- `warn` was added to the contract: `LogWriter` sinks must provide `debug/info/warn/error`, and `LogSeverity` gained `"warn"`.
- The package now ships dual ESM/CJS with types; deep imports (`@yingyeothon/logger/lib/...`) are no longer supported — import everything from the package root.
- `Logger`, `LogSeverity`, and `LogWriter` are type-only exports.

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