0.1.25 • Published 4 years ago

@nestjs.pro/logger-elasticsearch v0.1.25

Weekly downloads
1
License
MIT
Repository
github
Last release
4 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

4 years ago

0.1.11

4 years ago

0.1.12

4 years ago

0.1.13

4 years ago

0.1.14

4 years ago

0.1.15

4 years ago

0.1.20

4 years ago

0.1.21

4 years ago

0.1.22

4 years ago

0.1.23

4 years ago

0.1.24

4 years ago

0.1.25

4 years ago

0.1.16

4 years ago

0.1.17

4 years ago

0.1.18

4 years ago

0.1.19

4 years ago

0.1.9

4 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.0

5 years ago

0.1.1

5 years ago

0.0.12

5 years ago

0.0.13

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.5

5 years ago

0.0.6

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago