https://github.com/maxcharm093/module-logger-elasticsearch
Nestjs Elasticsearch Logger Module
https://github.com/maxcharm093/module-logger-elasticsearch
nestjs
Last synced: 4 months ago
JSON representation
Nestjs Elasticsearch Logger Module
- Host: GitHub
- URL: https://github.com/maxcharm093/module-logger-elasticsearch
- Owner: maxcharm093
- Created: 2025-08-24T18:31:50.000Z (11 months ago)
- Default Branch: dependabot/npm_and_yarn/ajv-6.12.6
- Last Pushed: 2025-08-24T18:38:22.000Z (11 months ago)
- Last Synced: 2025-08-24T22:50:32.812Z (11 months ago)
- Topics: nestjs
- Language: TypeScript
- Homepage:
- Size: 367 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Nestjs Elasticsearch Logger
## Installation
```bash
npm install @nestjs.pro/logger-elasticsearch
```
or
```bash
yarn add @nestjs.pro/logger-elasticsearch
```
## Setup
### Elasticsearch
First we need an elasticsearch instance (and optionally kibana for viewing logs).This repo comes with a `docker-compose.yaml` file to make things
easy for development. Simply `docker-compose up -d`.
### Bootstrapping
Import the `ElasticsearchLoggerModule` in your `AppModule` passing it a few configuration options:
```typescript
@Module({
imports: [
ElasticsearchLoggerModule.forRoot({
name: 'my-awesome-app',
index: 'logs',
stdout: true,
elasticsearchClientOptions: { nodes: 'http://localhost:9200' }
})
]
})
export class AppModule {
}
```
For more configuration options see https://github.com/nestjspro/module-logger-elasticsearch/blob/master/src/ElasticsearchLoggerOptions.ts.
## Usage
## Method Logging
Before we can log messages you simply need to inject the `ElasticsearchLoggerService` wherever you need to log messages at.
Example:
```typescript
@Injectable()
export class MyServiceOrController {
public constructor(private readonly elasticsearchLoggerService: ElasticsearchLoggerService) {
}
public someMethod(): void {
// do work
this.elasticsearchLoggerService.info('someMethod() called!');
}
}
```
## Controller Request Logging
You can optionally configure an interceptor and use the `ElasticsearchRequestInterceptor` to automagically log all of
your http requests. You can declare this at the global/app level or use at the controller level:
```typescript
import { Controller, UseInterceptors } from '@nestjs/common';
import { ElasticsearchRequestInterceptor } from '@nestjs.pro/logger-elasticsearch/dist/ElasticsearchRequestInterceptor';
@UseInterceptors(ElasticsearchRequestInterceptor)
@Controller('/mycontroller')
export class MyController {
// ...
}
```