Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/reference/index.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
---
applies_to:
stack: ga
serverless: ga
mapped_pages:
- https://www.elastic.co/guide/en/ecs-logging/nodejs/current/intro.html
- https://www.elastic.co/guide/en/ecs-logging/nodejs/current/index.html
---

# ECS Logging Node.js [intro]

Node.js ECS loggers are formatter plugins for your favorite logging libraries. They make it easy to format your logs into ECS-compatible JSON. In combination with [filebeat](https://www.elastic.co/products/beats/filebeat) you can send your logs directly to Elasticsearch and leverage [Kibanas Logs app](docs-content://solutions/observability/logs/explore-logs.md) to inspect all logs in one single place.
Node.js ECS loggers are formatter plugins for your favorite logging libraries. They make it easy to format your logs into ECS-compatible JSON. In combination with [filebeat](https://www.elastic.co/products/beats/filebeat) you can send your logs directly to Elasticsearch and leverage [Kibana's Logs app](docs-content://solutions/observability/logs/explore-logs.md) to inspect all logs in one single place.

The Node.js ECS logging formatters log structured JSON and support serialization of Error objects and HTTP Request and Response objects from Node.js core and popular web frameworks. A minimal log record includes the following fields:

Expand All @@ -30,5 +33,5 @@ Ready to jump into Node.js ECS logging?
* [ECS Logging with Winston](/reference/winston.md)
* [ECS Logging with Morgan](/reference/morgan.md)

If youd like to try out a tutorial using Node.js ECS logging with winston, see [Ingest logs from a Node.js web application using Filebeat](docs-content://manage-data/ingest/ingesting-data-from-applications/ingest-logs-from-nodejs-web-application-using-filebeat.md).
If you'd like to try out a tutorial using Node.js ECS logging with winston, see [Ingest logs from a Node.js web application using Filebeat](docs-content://manage-data/ingest/ingesting-data-from-applications/ingest-logs-from-nodejs-web-application-using-filebeat.md).

8 changes: 8 additions & 0 deletions docs/reference/morgan.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---

Check notice on line 1 in docs/reference/morgan.md

View workflow job for this annotation

GitHub Actions / docs-preview / build

Irregular space detected. Run 'docs-builder format --write' to automatically fix all instances.
applies_to:
stack: ga
serverless: ga
mapped_pages:
- https://www.elastic.co/guide/en/ecs-logging/nodejs/current/morgan.html
---
Expand Down Expand Up @@ -39,6 +42,11 @@

### Step 3: Configure Filebeat [morgan-setup-step-3]

```{applies_to}
stack: ga
serverless: unavailable
```

The best way to collect the logs once they are ECS-formatted is with [Filebeat](beats://reference/filebeat/index.md):

:::::::{tab-set}
Expand Down
12 changes: 10 additions & 2 deletions docs/reference/pino.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---

Check notice on line 1 in docs/reference/pino.md

View workflow job for this annotation

GitHub Actions / docs-preview / build

Irregular space detected. Run 'docs-builder format --write' to automatically fix all instances.
applies_to:
stack: ga
serverless: ga
mapped_pages:
- https://www.elastic.co/guide/en/ecs-logging/nodejs/current/pino.html
---
Expand Down Expand Up @@ -30,14 +33,19 @@
// ...
```

1. This will [configure](https://getpino.io/#/docs/api?id=options) Pinos `formatters`, `messageKey` and `timestamp` options.
1. This will [configure](https://getpino.io/#/docs/api?id=options) Pino's `formatters`, `messageKey` and `timestamp` options.


See usage discussion and examples below.


### Step 3: Configure Filebeat [pino-setup-step-3]

```{applies_to}
stack: ga
serverless: unavailable
```

The best way to collect the logs once they are ECS-formatted is with [Filebeat](beats://reference/filebeat/index.md):

:::::::{tab-set}
Expand Down Expand Up @@ -185,7 +193,7 @@
}
```

This is analogous to and overrides [Pinos default err serializer](https://getpino.io/#/docs/api?id=serializers-object). Special handling of the `err` field can be disabled via the `convertErr: false` option:
This is analogous to and overrides [Pino's default err serializer](https://getpino.io/#/docs/api?id=serializers-object). Special handling of the `err` field can be disabled via the `convertErr: false` option:

```js
const log = pino(ecsFormat({ convertErr: false }));
Expand Down
10 changes: 9 additions & 1 deletion docs/reference/winston.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---

Check notice on line 1 in docs/reference/winston.md

View workflow job for this annotation

GitHub Actions / docs-preview / build

Irregular space detected. Run 'docs-builder format --write' to automatically fix all instances.
applies_to:
stack: ga
serverless: ga
mapped_pages:
- https://www.elastic.co/guide/en/ecs-logging/nodejs/current/winston.html
---
Expand Down Expand Up @@ -41,6 +44,11 @@

### Step 3: Configure Filebeat [winston-setup-step-3]

```{applies_to}
stack: ga
serverless: unavailable
```

The best way to collect the logs once they are ECS-formatted is with [Filebeat](beats://reference/filebeat/index.md):

:::::::{tab-set}
Expand Down Expand Up @@ -168,7 +176,7 @@
{"@timestamp":"2023-10-14T02:14:17.304Z","log.level":"error","message":"oops there is a problem","ecs.version":"8.10.0","foo":"bar"}
```

The formatter handles serialization to JSON, so you dont need to add the [json](https://github.com/winstonjs/logform#json) formatter. As well, a timestamp is automatically generated by the formatter, so you dont need to add the [timestamp](https://github.com/winstonjs/logform#timestamp) formatter.
The formatter handles serialization to JSON, so you don't need to add the [json](https://github.com/winstonjs/logform#json) formatter. As well, a timestamp is automatically generated by the formatter, so you don't need to add the [timestamp](https://github.com/winstonjs/logform#timestamp) formatter.


## Error logging [winston-error-logging]
Expand Down
Loading