Socket
Socket
Sign inDemoInstall

nestjs-cloud-logging

Package Overview
Dependencies
308
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nestjs-cloud-logging

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


Version published
Weekly downloads
7
increased by75%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 15 Aug 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc