@elastic/ecs-morgan-format
TypeScript icon, indicating that this package has built-in type declarations

1.5.1 • Public • Published

@elastic/ecs-morgan-format

npm test

This Node.js package provides a formatter for the morgan logging middleware compatible with Elastic Common Schema (ECS) logging. In combination with the filebeat shipper, you can send your logs directly to Elasticsearch and leverage Kibana's Logs app to inspect all logs in one single place.

Please see the Node.js ECS morgan documentation.

Install

npm install @elastic/ecs-morgan-format

Usage

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:

% 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 for more.

License

This software is licensed under the Apache 2 license.

Package Sidebar

Install

npm i @elastic/ecs-morgan-format

Weekly Downloads

2,984

Version

1.5.1

License

Apache-2.0

Unpacked Size

23.9 kB

Total Files

5

Last publish

Collaborators

  • lenegadewoll
  • cbishopewc
  • cindy_c
  • asnyder-elastic
  • lgestc
  • 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