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

Able to pass a union type to logger in NestFactory.create to enable a partial logger while bootstraping #1838

Closed
iangregsondev opened this issue Mar 25, 2019 · 3 comments

Comments

@iangregsondev
Copy link

iangregsondev commented Mar 25, 2019


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I am going to try and word this one a little better as my previous issue didn't fully explain the issue. If its still not relevant, then feel free to close it. Although in my opinion its needed and a really nice feature

I am overwriting the system logger with my own (using log4js and by passing logger:false to NestFactory.create), on bootstrapping the application if there are any errors then nothing is output and just an unhelpful node crash report.

This is due to the fact that I pass logger:false to NestFactory.create, which allowed me to overwrite the logger but only after the bootstrapping of NestFactory.create has finished.

Can we change it, simple passing in some kind of string to logger, so it could be a partial logger

logger: boolean | string

So logger: false, disabled the logger completely, and logger: "ONLY-ERRORS" would continue to output errors but none of the INFO, because I will be overwriting after NestFactory.create returns.

of course ONLY-ERRORS can be some kind of ENUM

enum LoggerType {
   OnlyErrors = "ONLY-ERRORS"
   Off = "OFF"
}

So after NestFactory.create returns then I can continue with, which would REPLACE the partial system logger for ERROR for example.

  app.useLogger(app.get(SystemLogger));

The important thing here is that the system logger can work while bootstrapping so can offer ERRORS, but once we override it then that would REPLACE the Partial system logger that was enabled for producing ERROR outputs.

This would overwrite the logger function passed in above

This is due to the system bootstrapping and error out before arriving at my line to include my own custom logger i.e.

Environment


Nest version: 11
 
For Tooling issues:
- Node version: 6
- Platform:  Mac


@jmcdo29
Copy link
Member

jmcdo29 commented Mar 27, 2019

@appsolutegeek I ran into this issue a little while ago while using this in the start up code

const app = await NestFactory.create<NestFastifyApplication>(
      AppServerModule,
      new FastifyAdapter(),
      {
        logger: false
      }
    );

I found I was able to resolve it without the enums proposal by passing a new instance of my logging class to the create function

const app = await NestFactory.create<NestFastifyApplication>(
      AppServerModule,
      new FastifyAdapter(),
      {
        logger: new MyLogger()
      }
    );

Where MyLogger is the name of my logging service.

This allowed me to start seeing errors on application start up again.

However, I do think the proposed enum idea is cool, just thought I'd provide some sort of solution until that could happen.

@kamilmysliwiec
Copy link
Member

Log levels have been added in 6.6.0 :) I'll update the docs shortly

@lock
Copy link

lock bot commented Nov 26, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants