0.1.25 • Published 3 years ago

@nestjs.pro/logger-elasticsearch v0.1.25

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

Nestjs Elasticsearch Logger

Installation

npm install @nestjs.pro/logger-elasticsearch

or

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:

@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:

@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:

import { Controller, UseInterceptors } from '@nestjs/common';
import { ElasticsearchRequestInterceptor } from '@nestjs.pro/logger-elasticsearch/dist/ElasticsearchRequestInterceptor';

@UseInterceptors(ElasticsearchRequestInterceptor)
@Controller('/mycontroller')
export class MyController {

    // ...

}
0.1.10

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.14

3 years ago

0.1.15

3 years ago

0.1.20

3 years ago

0.1.21

3 years ago

0.1.22

3 years ago

0.1.23

3 years ago

0.1.24

3 years ago

0.1.25

3 years ago

0.1.16

3 years ago

0.1.17

3 years ago

0.1.18

3 years ago

0.1.19

3 years ago

0.1.9

3 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.0

4 years ago

0.1.1

4 years ago

0.0.12

4 years ago

0.0.13

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago