Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to let it work in nestjs lib and its initialization? #1283

Open
morty6688 opened this issue Nov 15, 2024 · 2 comments
Open

How to let it work in nestjs lib and its initialization? #1283

morty6688 opened this issue Nov 15, 2024 · 2 comments

Comments

@morty6688
Copy link

test repo

Here is the test repo: a simple nestjs project.
Only need two commands to start:

pnpm install
nest start --watch

And then call GET http://localhost:3000/hello to test.

actual result

In this example, it will output as following, not working in nestjs lib and its initialization:

[Nest] 15968  - 2024/11/16 06:07:36     LOG [NestFactory] Starting Nest application...
[Nest] 15968  - 2024/11/16 06:07:36     LOG [InstanceLoader] SharedModule dependencies initialized +6ms
[Nest] 15968  - 2024/11/16 06:07:36     LOG [InstanceLoader] AppModule dependencies initialized +0ms
[Nest] 15968  - 2024/11/16 06:07:36     LOG [InstanceLoader] Log4jsModule dependencies initialized +2ms
2024-11-16 06:07:36.539 [INFO] log4js.classes.js:38 - AppController {/}:
2024-11-16 06:07:36.541 [INFO] log4js.classes.js:38 - Mapped {/hello, GET} route
2024-11-16 06:07:36.543 [INFO] log4js.classes.js:38 - Nest application successfully started
2024-11-16 06:07:50.318 [INFO] app.controller.ts:14 - xxx Hello World!
@aquariuslt
Copy link
Member

please refer to nestjs use external logger

NestApplicationContextOptions#bufferLogs


import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Log4jsLogger } from "@nestx-log4js/core";

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    bufferLogs: true,
  });
  app.useLogger(app.get(Log4jsLogger));
  await app.listen(3000);
}

bootstrap();

@morty6688
Copy link
Author

please refer to nestjs use external logger

NestApplicationContextOptions#bufferLogs


import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Log4jsLogger } from "@nestx-log4js/core";

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    bufferLogs: true,
  });
  app.useLogger(app.get(Log4jsLogger));
  await app.listen(3000);
}

bootstrap();

thx for ur reply, it can work in initialization now. But the recorded file and line number in lib log is still log4js.classes.js:38, is it normal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants