async-deco
Advanced tools
Comparing version 4.0.0 to 4.1.0
{ | ||
"name": "async-deco", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "A collection of decorators for adding features to asynchronous functions (callback or promise based).", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -39,2 +39,37 @@ async-deco | ||
Logging | ||
======= | ||
All decorators use a common way to log whatever happens, using the "__log" method in the context (this). | ||
```js | ||
this.__log(name, id, ts, event, payload); | ||
``` | ||
This methods is called with the following arguments: | ||
* name: the name passed of the function | ||
* id: an id that changes every time you execute the function | ||
* ts: the time stamp for this event | ||
* evt: the name of the event | ||
* payload: an object with additional information about this event | ||
This method is used only if present and can be also added by the "log" decorator. | ||
This package contains an helper for adding it manually: | ||
```js | ||
var buildLogger = require('async-deco/utils/build-logger'); | ||
var context = buildLogger(undefined, 'name', 'id', function (name, id, ts, event, payload) { | ||
}); | ||
decoratedFunction.call(context, arg1, arg2, function (err, res) { | ||
... | ||
}); | ||
``` | ||
If you wish you can use this feature in your own decorators/functions: | ||
```js | ||
var defaultLogger = require('async-deco/utils/default-logger'); | ||
function myFunction() { | ||
var logger = defaultLogger.apply(this); | ||
... | ||
logger('myevent', {... additional info ...}); | ||
} | ||
``` | ||
Requiring the library | ||
@@ -70,4 +105,4 @@ ===================== | ||
``` | ||
name: is a string identifying this composed function. | ||
logger is a function taking these arguments: | ||
name: [optional] is a string identifying this composed function. | ||
logger [optional] is a function taking these arguments: | ||
* name: the name passed to the function | ||
@@ -74,0 +109,0 @@ * id: a random id that changes every time you execute the function |
@@ -1,2 +0,2 @@ | ||
var defaultLogger = require('./default-logger'); | ||
var defaultLogger = require('../utils/default-logger'); | ||
@@ -3,0 +3,0 @@ function cacheDecorator(wrapper, cache) { |
@@ -1,2 +0,2 @@ | ||
var defaultLogger = require('./default-logger'); | ||
var defaultLogger = require('../utils/default-logger'); | ||
@@ -3,0 +3,0 @@ function dedupeDecorator(wrapper, getKey) { |
@@ -1,2 +0,2 @@ | ||
var defaultLogger = require('./default-logger'); | ||
var defaultLogger = require('../utils/default-logger'); | ||
@@ -3,0 +3,0 @@ function fallbackCacheDecorator(wrapper, cache, error) { |
@@ -1,2 +0,2 @@ | ||
var defaultLogger = require('./default-logger'); | ||
var defaultLogger = require('../utils/default-logger'); | ||
@@ -3,0 +3,0 @@ function fallbackValueDecorator(wrapper, fallbackValue, error) { |
@@ -1,2 +0,2 @@ | ||
var defaultLogger = require('./default-logger'); | ||
var defaultLogger = require('../utils/default-logger'); | ||
@@ -3,0 +3,0 @@ function fallbackDecorator(wrapper, fallbackFunction, error) { |
require('setimmediate'); | ||
var defaultLogger = require('./default-logger'); | ||
var defaultLogger = require('../utils/default-logger'); | ||
@@ -4,0 +4,0 @@ function limitDecorator(wrapper, max, getKey) { |
@@ -1,3 +0,3 @@ | ||
var buildLogger = require('./build-logger'); | ||
var defaultLogger = require('./default-logger'); | ||
var buildLogger = require('../utils/build-logger'); | ||
var defaultLogger = require('../utils/default-logger'); | ||
@@ -8,3 +8,9 @@ function logDecorator(wrapper, log, name) { | ||
return function () { | ||
var context = buildLogger(this, name, log); | ||
var context, id; | ||
if (log) { | ||
id = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10); | ||
context = buildLogger(this, name, id, log); | ||
} else { | ||
context = this; | ||
} | ||
var args = Array.prototype.slice.call(arguments, 0); | ||
@@ -11,0 +17,0 @@ var logger = defaultLogger.apply(context); |
@@ -1,2 +0,2 @@ | ||
var defaultLogger = require('./default-logger'); | ||
var defaultLogger = require('../utils/default-logger'); | ||
@@ -3,0 +3,0 @@ function memoizeDecorator(wrapper, getKey) { |
@@ -1,2 +0,2 @@ | ||
var defaultLogger = require('./default-logger'); | ||
var defaultLogger = require('../utils/default-logger'); | ||
@@ -3,0 +3,0 @@ function proxyDecorator(wrapper, guard) { |
@@ -1,2 +0,2 @@ | ||
var defaultLogger = require('./default-logger'); | ||
var defaultLogger = require('../utils/default-logger'); | ||
@@ -3,0 +3,0 @@ function retryDecorator(wrapper, times, interval, error) { |
var TimeoutError = require('../errors/timeout-error'); | ||
var defaultLogger = require('./default-logger'); | ||
var defaultLogger = require('../utils/default-logger'); | ||
@@ -4,0 +4,0 @@ function timeout(wrapper, ms) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79242
2107
399