anylogger-debug
Advanced tools
Comparing version 1.1.0-beta.4 to 1.1.0-beta.5
@@ -1,20 +0,23 @@ | ||
(function () { | ||
var adapter = (function (anylogger, debug) { | ||
const extension = function (logger) { | ||
var method = debug(logger.name); | ||
for (var level in anylogger.levels) { | ||
logger[level] = method; | ||
} | ||
logger.enabledFor = debug.enabled.bind(logger, logger.name); | ||
return logger; | ||
}; | ||
const adapter = (anylogger) => { | ||
const adapter = (anylogger, debug) => { | ||
// bail early if it was already extended | ||
if (anylogger.debug) | ||
return; | ||
// override anylogger.ext() to make every log method use debug | ||
anylogger.ext = extension; | ||
anylogger.ext = function (logger) { | ||
var method = debug(logger.name); | ||
for (var level in anylogger.levels) { | ||
logger[level] = method; | ||
} | ||
logger.enabledFor = debug.enabled.bind(logger, logger.name); | ||
return logger; | ||
}; | ||
anylogger.debug = debug; | ||
}; | ||
// back compat | ||
adapter(anylogger); | ||
adapter(anylogger, debug); | ||
return adapter; | ||
})(); | ||
})(anylogger, debug); |
import anylogger from 'anylogger'; | ||
import debug from 'debug'; | ||
const extension = function (logger) { | ||
var method = debug(logger.name); | ||
for (var level in anylogger.levels) { | ||
logger[level] = method; | ||
} | ||
logger.enabledFor = debug.enabled.bind(logger, logger.name); | ||
return logger; | ||
}; | ||
const adapter = (anylogger) => { | ||
const adapter = (anylogger, debug) => { | ||
// bail early if it was already extended | ||
if (anylogger.debug) | ||
return; | ||
// override anylogger.ext() to make every log method use debug | ||
anylogger.ext = extension; | ||
anylogger.ext = function (logger) { | ||
var method = debug(logger.name); | ||
for (var level in anylogger.levels) { | ||
logger[level] = method; | ||
} | ||
logger.enabledFor = debug.enabled.bind(logger, logger.name); | ||
return logger; | ||
}; | ||
anylogger.debug = debug; | ||
}; | ||
export default adapter; | ||
// back compat | ||
adapter(anylogger); | ||
adapter(anylogger, debug); | ||
//# sourceMappingURL=anylogger-debug.js.map |
@@ -1,1 +0,1 @@ | ||
!function(){function n(e){var n,a=debug(e.name);for(n in anylogger.levels)e[n]=a;return e.enabledFor=debug.enabled.bind(e,e.name),e}var e=e=>{e.ext=n};e(anylogger)}(); | ||
var adapter=function(){var e=(a,d)=>{a.debug||(a.ext=function(e){var n,r=d(e.name);for(n in a.levels)e[n]=r;return e.enabledFor=d.enabled.bind(e,e.name),e},a.debug=d)};return e(anylogger,debug),e}(); |
import anylogger, { | ||
type LogLevel, | ||
type Logger, | ||
type Extension, | ||
type Adapter, | ||
@@ -9,20 +8,21 @@ } from 'anylogger' | ||
const extension: Extension = function(logger) { | ||
var method = debug(logger.name) | ||
for (var level in anylogger.levels) { | ||
(logger as Logger)[level as LogLevel] = method | ||
const adapter: Adapter = (anylogger, debug) => { | ||
// bail early if it was already extended | ||
if ((anylogger as any).debug) return | ||
// override anylogger.ext() to make every log method use debug | ||
anylogger.ext = function(logger) { | ||
var method = debug(logger.name) | ||
for (var level in anylogger.levels) { | ||
(logger as Logger)[level as LogLevel] = method | ||
} | ||
(logger as Logger).enabledFor = debug.enabled.bind(logger, logger.name) | ||
return logger as Logger | ||
} | ||
(logger as Logger).enabledFor = debug.enabled.bind(logger, logger.name) | ||
return logger as Logger | ||
// set a flag so we can see it was already extended | ||
;(anylogger as any).debug = debug | ||
} | ||
const adapter: Adapter = (anylogger) => { | ||
// override anylogger.ext() to make every log method use debug | ||
anylogger.ext = extension | ||
} | ||
export default adapter | ||
// back compat | ||
adapter(anylogger) | ||
adapter(anylogger, debug) |
{ | ||
"name": "anylogger-debug", | ||
"version": "1.1.0-beta.4", | ||
"version": "1.1.0-beta.5", | ||
"description": "Anylogger adapter for debug", | ||
@@ -28,3 +28,4 @@ "type": "module", | ||
"anylogger-debug.ts", | ||
"test.html" | ||
"test.html", | ||
"tsconfig.json" | ||
], | ||
@@ -63,3 +64,3 @@ "unpkg": "anylogger-debug.min.js", | ||
"@types/debug": "^4.1.12", | ||
"anylogger": "^1.1.0-beta.2", | ||
"anylogger": "^1.1.0-beta.4", | ||
"chai": "^5.1.0", | ||
@@ -66,0 +67,0 @@ "cross-env": "^7.0.3", |
@@ -1,2 +0,2 @@ | ||
# anylogger-debug <sub><sup>1.1.0-beta.4</sup></sub> | ||
# anylogger-debug <sub><sup>1.1.0-beta.5</sup></sub> | ||
### Anylogger adapter for debug | ||
@@ -19,6 +19,6 @@ | ||
* [anylogger-debug.js](https://unpkg.com/anylogger-debug@1.1.0-beta.4/anylogger-debug.js) | ||
* [anylogger-debug.js](https://unpkg.com/anylogger-debug@1.1.0-beta.5/anylogger-debug.js) | ||
(fully commented source ~5kB) | ||
* [anylogger-debug.min.js](https://unpkg.com/anylogger-debug@1.1.0-beta.4/anylogger-debug.min.js) | ||
(minified 167 bytes, gzipped ~[141](#gzip-size) bytes) | ||
* [anylogger-debug.min.js](https://unpkg.com/anylogger-debug@1.1.0-beta.5/anylogger-debug.min.js) | ||
(minified 199 bytes, gzipped ~[156](#gzip-size) bytes) | ||
@@ -30,5 +30,5 @@ | ||
```html | ||
<script src="https://unpkg.com/anylogger@1.1.0-beta.2/anylogger.min.js"></script> | ||
<script src="https://unpkg.com/anylogger-debug@1.1.0-beta.4/browserified-debug-4.1.1.min.js"></script> | ||
<script src="https://unpkg.com/anylogger-debug@1.1.0-beta.4/anylogger-debug.min.js"></script> | ||
<script src="https://unpkg.com/anylogger@1.1.0-beta.4/anylogger.min.js"></script> | ||
<script src="https://unpkg.com/anylogger-debug@1.1.0-beta.5/browserified-debug-4.1.1.min.js"></script> | ||
<script src="https://unpkg.com/anylogger-debug@1.1.0-beta.5/anylogger-debug.min.js"></script> | ||
<script>(function(){ // IIFE | ||
@@ -35,0 +35,0 @@ var log = anylogger('index.html') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
24011
14
322