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

setLogLevels is not a function #519

Closed
mgill2190 opened this issue Jun 30, 2022 · 2 comments
Closed

setLogLevels is not a function #519

mgill2190 opened this issue Jun 30, 2022 · 2 comments

Comments

@mgill2190
Copy link

Hey,

nestjs - 8.4.7
nest-winston - 1.6.2
winston - 3.8.0

On running npm run start:dev. I get the following error:

(node:75942) UnhandledPromiseRejectionWarning: TypeError: _a.setLogLevels is not a function
    at Function.overrideLogger (/node_modules/@nestjs/common/services/logger.service.js:121:90)
    at NestFactoryStatic.registerLoggerConfiguration (/node_modules/@nestjs/core/nest-factory.js:141:37)
    at NestFactoryStatic.createApplicationContext (/node_modules/@nestjs/core/nest-factory.js:72:14)
    at Function.runApplication (/packages/nest-commander/src/command.factory.ts:43:35)
    at Function.run (/packages/nest-commander/src/command.factory.ts:20:28)
    at bootstrap (/src/main.ts:28:24)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

main.ts -> bootstrap function has:

  const app = await NestFactory.create(AppModule);
  app.useLogger(WinstonModule.createLogger({
    format: winston.format.uncolorize(),
    transports: [
      new winston.transports.Console({
        format: winston.format.combine(
            winston.format.timestamp({
              format: 'YYYY-MM-DD HH:mm:ss',
            }),
            winston.format.ms(),
            nestWinstonModuleUtilities.format.nestLike()
        ),
      })
    ]
  }));

Error seems to be thrown from nest's logger service calling _a.setLogLevels(logger):

static overrideLogger(logger) {
      var _a;
      if (Array.isArray(logger)) {
          Logger_1.logLevels = logger;
          return (_a = this.staticInstanceRef) === null || _a === void 0 ? void 0 : _a.setLogLevels(logger);
      }
      if ((0, shared_utils_1.isObject)(logger)) {
          if (logger instanceof Logger_1 && logger.constructor !== Logger_1) {
              const errorMessage = `Using the "extends Logger" instruction is not allowed in Nest v8. Please, use "extends ConsoleLogger" instead.`;
              this.staticInstanceRef.error(errorMessage);
              throw new Error(errorMessage);
          }
          this.staticInstanceRef = logger;
      }
      else {
          this.staticInstanceRef = undefined;
      }
  }

Would really appreciate anyone showing some light on how I could get passed this issue? Thanks.

@nealoke
Copy link

nealoke commented Mar 16, 2023

A solution would be great when closing it 😄, @mgill2190

@mgill2190
Copy link
Author

@nealoke I didn't actually have a solution. A colleague managed to get Winston set up on nest without experiencing this issue. I pulled down his branch and worked fine so I assumed the issue was local to me and closed the issue to save someone else wasting time trying to fix.

Are you experiencing the same issue? Feel free to copy & paste above into new issue if you need help.

elia added a commit to elia/nest-winston that referenced this issue Aug 14, 2024
This method is used by NestJS when calling Logger.overrideLogger with
an array of log level names.

Ref. gremo#368 gremo#519
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