# @nr1e/logging

> Provides a standard logging pattern

Latest version **2.0.1** (published 2026-02-16) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @nr1e/logging
pnpm add @nr1e/logging
yarn add @nr1e/logging
bun add @nr1e/logging
```

## Health

**Score 60/100 (C)** — status: stable.

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

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2026-02-16 |
| First published | 2023-12-30 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 3 |
| Unpacked size | 71.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | NR1E, Inc. |
| Maintainers | nr1e |

## Links

- npm: https://www.npmjs.com/package/@nr1e/logging
- Repository: https://github.com/nr1etech/public
- Homepage: https://github.com/nr1etech/public#readme
- Issues: https://github.com/nr1etech/public/issues
- npm.io page: https://npm.io/package/@nr1e/logging

## Dependencies (3)

- [pino](https://npm.io/package/pino.md) ^10.3.1
- [sonic-boom](https://npm.io/package/sonic-boom.md) ^4.2.1
- [pino-abstract-transport](https://npm.io/package/pino-abstract-transport.md) ^3.0.0

## Recent versions

- 2.0.1 (latest) — 2026-02-16
- 0.0.0-snapshot-20260216205207 (snapshot) — 2026-02-16
- 1.6.1-beta.1733077950 (canary) — 2024-12-01
- 0.0.0-snapshot-20260216203739 — 2026-02-16
- 2.0.0 — 2025-12-28
- 0.0.0-snapshot-20251228031344 — 2025-12-28
- 1.6.1 — 2025-12-28
- 0.0.0-snapshot-20251228003719 — 2025-12-28
- 0.0.0-snapshot-20251228003135 — 2025-12-28
- 1.6.1-alpha.0 — 2025-12-28
- 1.6.0 — 2024-12-01
- 1.6.0-beta.1733009173 — 2024-11-30
- 1.6.0-beta.1732994691 — 2024-11-30
- 1.6.0-beta.1732994182 — 2024-11-30
- 1.6.0-beta.1732983618 — 2024-11-30
- … 101 more at https://npm.io/package/@nr1e/logging/versions

## README

# Logging

[![NPM Version][npm-image]][npm-url]

Provides a simple logging interface for typescript projects that
adheres to the NR1E logging standard. The goal of this wrapper is to
reduce CPU and memory overhead by only formatting log messages when
the log level is set to a level that would allow the message to be logged.

To install using `pnpm`

```bash
pnpm i @nr1e/logging
```

## How to use

Initialize logging in your application.

```typescript
import * as logging from '@nr1e/logging';

// This only needs to be performed once
logging.initialize({
    svc: 'my-service',
    level: 'info',
});
```

To obtain a named child logger of the root logger

```typescript
const log = logging.getLogger('my-module');
```

To obtain a named child logger of another logger

```typescript
const log = logging.getLogger('my-module', parentLogger);
```

To add a permanent context to a logger

```typescript
log.ctx({foo: 'bar'});
```

To log an info message

```typescript
log.info().msg('Just another day in the life of a logger');
```

To log a message with a context

```typescript
log.info().obj({foo: 'bar'}).msg('Just another day in the life of a logger');
```

You can also log nested objects

```typescript
log.info().obj({foo: 'bar', nested: {foo: 'bar'}}).msg('Just another day in the life of a logger');
);
```

To log an error

```typescript
try {
    throw new Error('An error occurred');
} catch (err) {
    log.error()
        .err(err)
        .msg(
            'Human sacrifice, dogs and cats living together... MASS HYSTERIA!',
        );
}
```

To log an error with additional context

```typescript
try {
    throw new Error('An error occurred');
} catch (err) {
    log.error()
        .err(err)
        .obj({foo: 'bar'})
        .msg(
            'Human sacrifice, dogs and cats living together... MASS HYSTERIA!',
        );
}
```

[npm-url]: https://npmjs.com/package/@nr1e/logging
[npm-image]: https://img.shields.io/npm/v/@nr1e/logging.svg

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