1.0.17 • Published 1 year ago

@nest-gcr/logger v1.0.17

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Installation

  1. Install the dependency
yarn add @nest-gcr/logger
  1. Register the module
import { Module } from '@nestjs/common';
import { LoggerModule } from '@nest-gcr/logger';

@Module({
  imports: [LoggerModule]
})
export class AppModule {}

Usage

  1. Use it anywhere in your application. You have access to two providers:
import { Inject, Injectable } from '@nestjs/common';
import { LOGGER, Logger } from '@nest-gcr/logger'

@Injectable()
export class MyProvider {
  constructor(
    @Inject(LOGGER.PROVIDERS.LOGGER) logger: Logger,
    @Inject(LOGGER.PROVIDERS.REQUEST_LOGGER) requestLogger: Logger
  ) {}
  
  foo () {
    this.requestLogger.debug('Hello World!')
  }
}
  1. Use the global logger for default nestJS logs:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { rootLogger } from '@nest-gcr/logger';

async function bootstrap() {
  const app = await NestFactory.create(TestModule, {
    logger: {
      ...rootLogger,
      log: (message, parameters) => {
        return rootLogger.info(message, parameters);
      },
      error: (message, parameters) => {
        return rootLogger.error(message, parameters)
      }
    },
  });
  await app.listen(process.env.PORT || 3000);
}

bootstrap();

Configuration on Google Cloud RUN

In order for logs to be correctly logged to Google Cloud Logging from Cloud Run instances, you need to set the following environment variable into your container:

LOGGER_DRIVER=gcp

Change Log

See Changelog for more information.

Contributing

Contributions welcome! See Contributing.

Author

John Biundo (Y Prospect on Discord)

License

Licensed under the MIT License - see the LICENSE file for details.

1.0.17

1 year ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago