# @matrixai/logger

> Python-like JavaScript Logger

Latest version **4.0.3** (published 2025-02-04) · Apache-2.0 license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 4.0.3 |
| Published | 2025-02-04 |
| First published | 2021-02-16 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 47.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Roger Qiu |
| Maintainers | brianbotha74, cmcdragonkai, matrixai-bot |

## Links

- npm: https://www.npmjs.com/package/@matrixai/logger
- Repository: https://github.com/MatrixAI/js-logger
- Homepage: https://github.com/MatrixAI/js-logger#readme
- Issues: https://github.com/MatrixAI/js-logger/issues
- npm.io page: https://npm.io/package/@matrixai/logger

## Recent versions

- 4.0.3 (latest) — 2025-02-04
- 4.0.4-alpha.5 (prerelease) — 2025-05-12
- 4.0.4-alpha.4 — 2025-05-07
- 4.0.4-alpha.3 — 2025-04-30
- 4.0.4-alpha.2 — 2025-04-30
- 4.0.4-alpha.1 — 2025-04-28
- 4.0.4-alpha.0 — 2025-04-17
- 4.0.2 — 2023-11-15
- 3.1.3 — 2023-11-15
- 3.1.2 — 2023-11-08
- 3.1.1 — 2023-11-08
- 4.0.1 — 2023-08-12
- 3.1.0 — 2022-11-23
- 3.0.0 — 2022-07-21
- 2.3.0 — 2022-06-29
- … 8 more at https://npm.io/package/@matrixai/logger/versions

## README

# js-logger

This library provides a JavaScript/TypeScript logger inspired by Python's logger.

* Simple logging with default handlers supporting `console.log`, `console.error`, and `process.stderr`.
* Fast, logging level checks or log filters are applied **before** log records are created
* Complex log records properties ssupport lazy evaluation, so they evaluated only when they need to be rendered
* Flexible composition of loggers, handlers and formatters
* Custom formatting using template literals
* Supports structured logging through a JSON formatter
* Supports hierarchical logging through parent-child logger graph
* CI/CD tests on Linux, MacOS and Windows
* Zero runtime dependencies!
* Comprehensive continuous benchmarks in CI/CD

## Installation

```sh
npm install --save @matrixai/logger
```

## Usage

```ts
import Logger, { LogLevel, StreamHandler, formatting } from '@matrixai/logger';

const logger = new Logger('root', LogLevel.INFO, [
  new StreamHandler(
    formatting.format`${formatting.date}:${formatting.level}:${formatting.key}:${formatting.msg}:${formatting.data}`,
  ),
]);

logger.debug('Hello world', { a: { b: [123, 456] } });
logger.info('Hello world', { 123: { b: [123, 456] } });
logger.warn('Hello world', { lazy: () => 'string' });
logger.error('Hello world', formatting.format`my custom format`);

const loggerChild = logger.getChild('child');

loggerChild.info(
  'Hello world',
  { 123: { b: [123, 456] } },
  formatting.format`${formatting.keys}:${formatting.msg}:${formatting.data}`,
);
```

There's lots more options available in the source code. See the docs and see the source code for more details.

## Development

Run `nix develop`, and once you're inside, you can use:

```sh
# install (or reinstall packages from package.json)
npm install
# build the dist
npm run build
# run the repl (this allows you to import from ./src)
npm run tsx
# run the tests
npm run test
# lint the source code
npm run lint
# automatically fix the source
npm run lintfix
```

### Docs Generation

```sh
npm run docs
```

See the docs at: https://matrixai.github.io/js-logger/

### Publishing

Publishing is handled automatically by the staging pipeline.

Prerelease:

```sh
# npm login
npm version prepatch --preid alpha # premajor/preminor/prepatch
git push --follow-tags
```

Release:

```sh
# npm login
npm version patch # major/minor/patch
git push --follow-tags
```

Manually:

```sh
# npm login
npm version patch # major/minor/patch
npm run build
npm publish --access public
git push
git push --tags
```

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