# h-logger2-elastic

> Elasticsearch and APM integration for h-logger2

Latest version **7.0.1** (published 2026-05-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install h-logger2-elastic
pnpm add h-logger2-elastic
yarn add h-logger2-elastic
bun add h-logger2-elastic
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 7.0.1 |
| Published | 2026-05-07 |
| First published | 2018-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 12.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Martin Kolárik |
| Maintainers | martin-kolarik |

## Links

- npm: https://www.npmjs.com/package/h-logger2-elastic
- Repository: https://github.com/MartinKolarik/h-logger2-elastic
- Homepage: https://github.com/MartinKolarik/h-logger2-elastic#readme
- Issues: https://github.com/MartinKolarik/h-logger2-elastic/issues
- npm.io page: https://npm.io/package/h-logger2-elastic

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^4.18.1
- [promise-retry](https://npm.io/package/promise-retry.md) ^2.0.1
- [safe-json-stringify](https://npm.io/package/safe-json-stringify.md) ^1.2.0
- [@martin-kolarik/batch-queue](https://npm.io/package/@martin-kolarik/batch-queue.md) ^1.1.1

## Recent versions

- 7.0.1 (latest) — 2026-05-07
- 7.0.0 — 2025-05-20
- 6.2.1 — 2024-12-10
- 6.2.0 — 2024-12-10
- 6.1.2 — 2024-12-05
- 6.1.1 — 2024-12-05
- 6.1.0 — 2024-12-04
- 6.0.0 — 2024-12-03
- 5.0.1 — 2023-08-11
- 5.0.0 — 2023-08-11
- 4.0.2 — 2022-05-08
- 4.0.1 — 2022-03-30
- 4.0.0 — 2022-03-30
- 3.0.1 — 2021-07-02
- 3.0.0 — 2019-06-05
- … 10 more at https://npm.io/package/h-logger2-elastic/versions

## README

# h-logger2-elastic

Elasticsearch and APM integration for [h-logger2](https://github.com/MartinKolarik/h-logger2).

## Installation

```
$ npm install h-logger2-elastic
```

Follow [this guide](https://www.elastic.co/guide/en/elasticsearch/reference/current/set-up-a-data-stream.html) to create:
1. a component template `logs-logger` based on `src/template.json`
2. an index template `logs-logger-*`
3. and finally a data stream `logs-logger-default`

## Usage

```js
const Logger = require('h-logger2');
const ElasticWriter = require('h-logger2-elastic');

const logger = new Logger('my-app-name', [ new Logger.ElasticWriter(Logger.TRACE, {
    esClient, // instance of elasticsearch client (https://github.com/elastic/elasticsearch-js)
    apmClient, // optional, instance of APM client (https://github.com/elastic/apm-agent-nodejs)
}) ]);
```

When `apmClient` is gived, messages with levels `error` and `fatal` are captured as APM errors instead of being sent to the regular elasticsearch index.

## License
Copyright (c) 2018 - 2019 Martin Kolárik. Released under the MIT license.

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