# @fastify/one-line-logger

> A simple formatter for fastify's logs

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

## Install

```sh
npm install @fastify/one-line-logger
pnpm add @fastify/one-line-logger
yarn add @fastify/one-line-logger
bun add @fastify/one-line-logger
```

## Health

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

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2026-08-08 |
| First published | 2022-08-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 33.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 47 |
| Author | Matteo Collina |
| Maintainers | jsumners, eomm, climba03003, gurgunday, fdawgs, ivan-tymoshenko |
| Keywords | fastify, logger, pino, pino-pretty, one-line-logger |

## Links

- npm: https://www.npmjs.com/package/@fastify/one-line-logger
- Repository: https://github.com/fastify/one-line-logger
- Homepage: https://github.com/fastify/one-line-logger#readme
- Issues: https://github.com/fastify/one-line-logger/issues
- Funding: https://github.com/sponsors/fastify
- npm.io page: https://npm.io/package/@fastify/one-line-logger

## Dependencies (2)

- [dateformat](https://npm.io/package/dateformat.md) ^5.0.3
- [pino-pretty](https://npm.io/package/pino-pretty.md) ^13.0.0

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

- 2.2.0 (latest) — 2026-08-08
- 2.0.0-pre.fv5.1 (next) — 2024-06-16
- 2.1.0 — 2026-01-10
- 2.0.2 — 2025-01-11
- 2.0.1 — 2024-11-12
- 2.0.0 — 2024-09-06
- 1.4.0 — 2024-06-12
- 1.3.0 — 2024-03-19
- 1.2.0 — 2023-05-14
- 1.1.1 — 2022-12-05
- 1.1.0 — 2022-12-05
- 1.0.0 — 2022-08-17

## README

<a id="@fastify/one-line-logger"></a>
# @fastify/one-line-logger


[![CI](https://github.com/fastify/one-line-logger/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/one-line-logger/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/one-line-logger.svg?style=flat)](https://www.npmjs.com/package/@fastify/one-line-logger)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

`@fastify/one-line-logger` helps you format fastify's log into a nice one-line message:

```
YYYY-MM-dd HH:mm:ss.SSSTZ - <level> - <method> <route path> - <message>
```

A standard incoming request log line like:

```
{"level": 30,"time": 1660151282194,"pid": 1557,"hostname": "foo","reqId": "req-1","req": {"method": "GET","url": "/path","hostname": "localhost:8080","remoteAddress": "127.0.0.1"},"msg": "incoming request"}
```

Will format to:

```
2022-08-11 01:08:02.194+0100 - info - GET / - incoming request
```

<a id="install"></a>
## Install

```
npm i @fastify/one-line-logger
```

<a id="getting-started"></a>
## Getting started

```js
const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
    },
  },
});
```

## Colors

Colors are enabled by default when supported. To manually disable the colors you need to set the `transport.colorize` option to `false`. For more options check the `colorette` [docs](https://github.com/jorgebucaran/colorette?tab=readme-ov-file#environment).

```js
const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
      colorize: false,
    },
  },
});
```


## Custom levels

Custom levels could be used by passing it into logger opts

```js
const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
    },
    customLevels: {
      foo: 35,
      bar: 45,
    },
  },
});

server.get("/", (request, reply) => {
  request.log.info("time to foobar");
  request.log.foo("FOO!");
  request.log.bar("BAR!");
  reply.send({ foobar: true });
});
```

## Custom level colors

Custom level colors can be used by passing it into logger opts. They can also overwrite the default level's colors. Check all the supported colors [here](https://github.com/jorgebucaran/colorette?tab=readme-ov-file#supported-colors).

```js
const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
      options: {
        colors: {
          35: "bgYellow",
          45: "magenta",
          60: "bgRedBright" // overwriting the `fatal` log color
        }
      }
    },
    customLevels: {
      foo: 35,
      bar: 45,
    },
  },
});

server.get("/", (request, reply) => {
  request.log.fatal("An error occurred");
  request.log.foo("FOO!");
  request.log.bar("BAR!");
  reply.send({ foobar: true });
});
```

## Time-only format

To output only the time without the date and timezone:

```js
const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
      options: { timeOnly: true }
    }
  }
});
```

Output: `01:08:02.194 - info - GET / - incoming request`

## Custom time format

Use the `customTimeFormat` option with a [dateformat](https://www.npmjs.com/package/dateformat) pattern:

```js
const server = fastify({
  logger: {
    transport: {
      target: "@fastify/one-line-logger",
      options: { customTimeFormat: "HH:MM:ss" }
    }
  }
});
```

Common patterns:
- `"HH:MM:ss"` → `01:08:02`
- `"yyyy-mm-dd HH:MM:ss"` → `2022-08-11 01:08:02`
- `"isoDateTime"` → `2022-08-11T01:08:02+0100`

**Note:** `timeOnly` and `customTimeFormat` are mutually exclusive and cannot be used together.

<a id="license"></a>
## License

Licensed under [MIT](./LICENSE).

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