Skip to content

Commit

Permalink
Move Logging Sample To Error Section
Browse files Browse the repository at this point in the history
Updated and moved logging sample to new Error Logging subsection
  • Loading branch information
Tyharo1 committed Feb 12, 2020
1 parent cb149a8 commit d127103
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions README.md
Expand Up @@ -1151,21 +1151,6 @@ Defaults:
- _schemas_: an array or object of schemas that will be added to the instance. In case you pass the array the schemas must have IDs in them. When the object is passed the method `addSchema(value, key)` will be called for each schema in this object.
- _logger_: sets the logging method. Default is the global `console` object that should have methods `log`, `warn` and `error`. Option values:
- custom logger - it should have methods `log`, `warn` and `error`. If any of these methods is missing an exception will be thrown.
```javascript
var ajv = new Ajv({
logger: {
log: function log(_log) {
return console.log(_log);
},
warn: function warn(_warn) {
return console.warn("Custom Warning: ".concat(_warn));
},
error: function error(_error) {
return console.error(_error);
}
}
});
```
- `false` - logging is disabled.


Expand Down Expand Up @@ -1302,6 +1287,30 @@ Properties of `params` object in errors depend on the keyword that failed valida
- custom keywords (in case keyword definition doesn't create errors) - property `keyword` (the keyword name).


### Error Logging

Using the `logger` option when initiallizing Ajv will allow you to define custom logging. Here you can build upon the exisiting logging. The use of other logging packages is supported as long as the package or its associated wrapper exposes the required methods. If any of the required methods are missing an exception will be thrown.
- **Required Methods**: `log`, `warn`, `error`

```javascript
var otherLogger = new OtherLogger();
var ajv = new Ajv({
logger: {
log: function log(_log) {
return console.log(_log);
},
warn: function warn(_warn) {
return otherLogger.logWarn(_warn);
},
error: function error(_error) {
otherLogger.logError(_error);
return console.error(_error);
}
}
});
```


## Plugins

Ajv can be extended with plugins that add custom keywords, formats or functions to process generated code. When such plugin is published as npm package it is recommended that it follows these conventions:
Expand Down

0 comments on commit d127103

Please sign in to comment.