# @elastic/ecs-morgan-format

> A formatter for the morgan logger compatible with Elastic Common Schema.

Latest version **1.5.1** (published 2023-11-23) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @elastic/ecs-morgan-format
pnpm add @elastic/ecs-morgan-format
yarn add @elastic/ecs-morgan-format
bun add @elastic/ecs-morgan-format
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.5.1 |
| Published | 2023-11-23 |
| First published | 2020-02-11 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 2 |
| Unpacked size | 23.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 69 |
| Author | Tomas Della Vedova |
| Maintainers | patryk.kopycinski, banerjeesoham004, legrego, bradtimmerman, devcorpio, yan.savitski, jeramysoucy, tkajtoch, johnwcambra, colleen.mcginnis, scottybollinger, kyrspl, phoey1, verogo, breehall, trevorpierce, glitteringkatie, jen-huang, delvedor, lukasolson, ccowan, jbudz, thomasneirynck, weltenwort, pugnascotia, zinckiwi, brandon.kobel, nreese, mgreau, jonahbull, jarpy, leathekd, lukeelmers, ddillinger, joshdover, jasonstoltz, bamieh, markov00, joshmock, vignesh.shanmugam, watson, rhodesjason, jmlrt, mattkime, constancecchen, afoucret, nickpeihl, axw, mistic, elasticmachine, gtback, pickypg, trentm, andrewvc-elastic, jorge.sanz, stratoula, nkammah, streamich, nickofthyme, chloeruka |
| Keywords | morgan, express, serializer, formatter, elasticsearch, ecs, ecs-logging, elastic, common, schema |

## Links

- npm: https://www.npmjs.com/package/@elastic/ecs-morgan-format
- Repository: https://github.com/elastic/ecs-logging-nodejs
- Homepage: https://github.com/elastic/ecs-logging-nodejs/blob/main/packages/ecs-morgan-format/README.md
- Issues: https://github.com/elastic/ecs-logging-nodejs/issues
- npm.io page: https://npm.io/package/@elastic/ecs-morgan-format

## Dependencies (2)

- [@elastic/ecs-helpers](https://npm.io/package/@elastic/ecs-helpers.md) ^2.1.1
- [safe-stable-stringify](https://npm.io/package/safe-stable-stringify.md) ^2.4.3

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

- 1.5.1 (latest) — 2023-11-23
- 1.5.0 — 2023-10-31
- 1.4.0 — 2023-10-17
- 1.1.0 — 2021-03-19
- 1.0.0 — 2021-02-08
- 0.3.0 — 2021-01-06
- 0.2.0 — 2020-03-16
- 0.1.0 — 2020-02-11

## README

<img align="right" width="auto" height="auto" src="https://www.elastic.co/static-res/images/elastic-logo-200.png">

# @elastic/ecs-morgan-format

[![npm](https://img.shields.io/npm/v/@elastic/ecs-morgan-format.svg)](https://www.npmjs.com/package/@elastic/ecs-morgan-format)
[![test](https://github.com/elastic/ecs-logging-nodejs/actions/workflows/test.yml/badge.svg)](https://github.com/elastic/ecs-logging-nodejs/actions/workflows/test.yml)

This Node.js package provides a formatter for the
[morgan](https://github.com/expressjs/morgan) logging middleware compatible with
[Elastic Common Schema (ECS) logging](https://www.elastic.co/guide/en/ecs-logging/overview/master/intro.html).
In combination with the [filebeat](https://www.elastic.co/products/beats/filebeat)
shipper, you can send your logs directly to Elasticsearch and leverage
[Kibana's Logs app](https://www.elastic.co/guide/en/observability/current/monitor-logs.html)
to inspect all logs in one single place.

Please see the [Node.js ECS morgan documentation](https://www.elastic.co/guide/en/ecs-logging/nodejs/current/morgan.html).


## Install

```sh
npm install @elastic/ecs-morgan-format
```

## Usage

```js
const app = require('express')()
const morgan = require('morgan')
const { ecsFormat } = require('@elastic/ecs-morgan-format')

app.use(morgan(ecsFormat(/* options */)))

app.get('/', function (req, res) {
  res.send('hello, world!')
})

app.listen(3000)
```

Running this script and making a request (via `curl -i localhost:3000/`) will
produce log output similar to the following:

```sh
% node examples/express.js | jq .  # piping to jq for pretty-printing
{
  "@timestamp": "2023-10-16T22:00:33.782Z",
  "log.level": "info",
  "message": "::ffff:127.0.0.1 - - [16/Oct/2023:22:00:33 +0000] \"GET / HTTP/1.1\" 200 13 \"-\" \"curl/8.1.2\"",
  "http": {
    "version": "1.1",
    "request": {
      "method": "GET",
      "headers": {
        "host": "localhost:3000",
        "user-agent": "curl/8.1.2",
        "accept": "*/*"
      }
    },
    "response": {
      "status_code": 200,
      "headers": {
        "x-powered-by": "Express",
        "content-type": "text/html; charset=utf-8",
        "content-length": "13",
        "etag": "W/\"d-HwnTDHB9U/PRbFMN1z1wps51lqk\""
      },
      "body": {
        "bytes": 13
      }
    }
  },
  "url": {
    "path": "/",
    "domain": "localhost",
    "full": "http://localhost:3000/"
  },
  "client": {
    "address": "::ffff:127.0.0.1",
    "ip": "::ffff:127.0.0.1",
    "port": 60455
  },
  "user_agent": {
    "original": "curl/8.1.2"
  },
  "ecs.version": "8.10.0"
}
```

Please see the [Node.js ECS morgan documentation](https://www.elastic.co/guide/en/ecs-logging/nodejs/current/morgan.html) for more.

## License

This software is licensed under the [Apache 2 license](./LICENSE).

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