JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 128
  • Score
    100M100P100Q69408F
  • License MIT

Extended default NestJS logger with Winston transporter for Google Cloud Logging.

Package Exports

  • nestjs-cloud-logging
  • nestjs-cloud-logging/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nestjs-cloud-logging) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

nestjs-cloud-logging

Extended default NestJS logger with Winston transporter for Google Cloud Logging.

1. Replace default logger when bootstraping

// main.ts
import {WinstonLoggerServiceApp} from 'nestjs-cloud-logging';

async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    app.useLogger(app.get(WinstonLoggerServiceApp));

    await app.listen(3000);
}

bootstrap();

2. Import logger module into root module and registering it globally

// app.module.ts
import {WinstonLoggerModule} from 'nestjs-cloud-logging';

@Module({
    imports: [
        WinstonLoggerModule.forRoot({
            isGlobal: true,
            projectId: "google-cloud-project-id",
            keyFilename: "path-to-key-filename",
        }),
    ],
    controllers: [],
    providers: [],
})
export class AppModule {
}

3. How to inject logger anywhere

import {Logger, LoggerService} from 'nestjs-cloud-logging';

@Injectable()
export class UserService {
    constructor(@Logger() private readonly logger: LoggerService) {
    }

    getUser(id: number): Promise<User> {
        this.logger.log('Your logger message');
        return this.userRepository.getUser(id);
    }
}

4. Google Cloud Logging - this is available metadata in every subsequental log insert for request

img.png