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

Disable logging for query #344

Closed
kennyevo opened this issue Jun 5, 2020 · 1 comment · Fixed by #345
Closed

Disable logging for query #344

kennyevo opened this issue Jun 5, 2020 · 1 comment · Fixed by #345
Labels
question Further information is requested

Comments

@kennyevo
Copy link

kennyevo commented Jun 5, 2020

Hi!

I'm using a unique field to check if an item already in the db, and checking the result in the Future.
Currently I'm logging if an entity is already in the db, but fluent is logging the error by default.

Is it possible to silence the error? Or set a custom logger in vapor4?

Thanks in advance, and sorry if it's a noob question

@tanner0101 tanner0101 transferred this issue from vapor/fluent Jul 12, 2020
@tanner0101 tanner0101 added the question Further information is requested label Jul 12, 2020
@tanner0101
Copy link
Member

tanner0101 commented Jul 12, 2020

You should be able to temporarily set the request's log level to something higher than error (like critical). For example:

req.logger.logLevel = .critical
doQuery(on: req.db).flatMap {
    req.logger.logLevel = .info
}

I've also put up a PR (#345) that adds a logging(to:) method to Database for temporarily overriding the logger. You can use the same method of creating a new logger with its log level changed, but with logging(to:) you can more precisely set just the database's logger.

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

Successfully merging a pull request may close this issue.

2 participants