Skip to content
New issue

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

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

Already on GitHub? # to your account

Configuration for console logging #618

Closed
meirotstein opened this issue Nov 8, 2017 · 3 comments
Closed

Configuration for console logging #618

meirotstein opened this issue Nov 8, 2017 · 3 comments

Comments

@meirotstein
Copy link
Contributor

What version of Ajv you are you using?
5.1.3

What problem do you want to solve?
Ajv uses console.warn to report some warnings to the console.
I had several issues with some consumers of my package (which uses Ajv) that on there site they have a customized version of the console object and they don't interested with the Ajv warnings, in some cases the customized version did not implemented the warn function what leads to an Error.

This force these kind of sites to change the implementation of the console object in order to use packages that are depended in Ajv - which is not so easy when it comes to a large scale sites of big firms.

What do you think is the correct solution to problem?
I think that there should be a new option: consoleLog, default true, that when set to false there will be no reports to the console object whatsoever.

Will you be able to implement it?
Yes

@epoberezkin
Copy link
Member

@meirotstein that's good, thank you.

I suggest calling the option logger and support:

  • false to suppress all logging (but not exceptions)
  • a custom logger object with methods log, warn, error

By default Ajv would simply assign console to this option.
There should be tests for all cases for all existing calls to console.

I don't think there is any logging during validation apart from $comment keyword but it is off by default and it has its own option that enables it.

@meirotstein
Copy link
Contributor Author

HI @epoberezkin

I like your suggestion - sounds better than just a simple boolean option.

As for the current logging - you can find a call for console.warn() here, here and here

@epoberezkin
Copy link
Member

in 5.4.0

# for free to join this conversation on GitHub. Already have an account? # to comment
Development

No branches or pull requests

2 participants