Comparing version 1.2.0 to 1.3.0
@@ -11,5 +11,11 @@ import { IDebugger } from 'debug'; | ||
} | ||
export declare function getLogger(ns: string, context?: string, cache?: boolean): Logger; | ||
export interface LoggerOptions { | ||
ns: string; | ||
context?: string; | ||
cache?: boolean; | ||
} | ||
export declare function getLogger(ns: string, context?: string, cache?: boolean): any; | ||
export declare function getLogger(opts: LoggerOptions): Logger; | ||
export declare function namespaces(): string[]; | ||
export declare function cb(ns?: string): (err: any, data?: any) => void; | ||
export declare function promise(p: PromiseLike<any>, ns?: string): PromiseLike<any>; |
@@ -9,28 +9,22 @@ "use strict"; | ||
const __loggers = {}; | ||
function createLogger(ns, context) { | ||
let d = context | ||
? function (label) { | ||
let origDebugger = debug(label); | ||
let wrappedDebugger = function (formatter, ...args) { | ||
origDebugger(`${context} ${formatter}`, ...args); | ||
}; | ||
['namespace', 'enabled', 'userColors', 'color'].forEach(i => { | ||
wrappedDebugger[i] = origDebugger[i]; | ||
}); | ||
wrappedDebugger['destroy'] = () => origDebugger['destroy'](); | ||
Object.defineProperty(wrappedDebugger, 'log', { | ||
get: () => origDebugger.log, | ||
set: v => (origDebugger.log = v) | ||
}); | ||
return wrappedDebugger; | ||
} | ||
: debug; | ||
let out = { | ||
log: d(ns + ':log'), | ||
info: d(ns + ':info'), | ||
warn: d(ns + ':warn'), | ||
error: d(ns + ':error'), | ||
debug: d(ns + ':debug'), | ||
trace: d(ns + ':trace') | ||
}; | ||
function wrap(opts, type) { | ||
const d = debug(`${opts.ns}:${type}`); | ||
if (opts.context) { | ||
const handler = { | ||
apply: function (target, thisArg, argumentList) { | ||
const [formatter, ...args] = argumentList; | ||
return target.call(thisArg, `${opts.context} ${formatter}`, ...args); | ||
}, | ||
}; | ||
return new Proxy(d, handler); | ||
} | ||
else { | ||
return d; | ||
} | ||
} | ||
function createLogger(opts) { | ||
let out = ['log', 'info', 'warn', 'error', 'debug', 'trace'].reduce((out, key) => { | ||
out[key] = wrap(opts, key); | ||
return out; | ||
}, {}); | ||
if (typeof window === 'object' && typeof window.console === 'object') { | ||
@@ -49,6 +43,7 @@ try { | ||
} | ||
function getLogger(ns, context, cache) { | ||
function getLogger(nsOrOpts, context, cache) { | ||
const opts = typeof nsOrOpts === 'string' ? { ns: nsOrOpts, context, cache } : nsOrOpts; | ||
let out; | ||
if (cache === false) { | ||
out = createLogger(ns, context); | ||
if (opts.cache === false) { | ||
out = createLogger(opts); | ||
for (let i in out) { | ||
@@ -59,6 +54,6 @@ out[i].destroy(); // this is to avoid caching forever in debug.instances | ||
else { | ||
let cacheKey = context ? `${ns}@@${context}` : ns; | ||
let cacheKey = opts.context ? `${opts.ns}@@${opts.context}` : opts.ns; | ||
if (!__loggers[cacheKey]) { | ||
__namespaces[ns] = true; | ||
__loggers[cacheKey] = createLogger(ns, context); | ||
__namespaces[opts.ns] = true; | ||
__loggers[cacheKey] = createLogger(opts); | ||
} | ||
@@ -65,0 +60,0 @@ out = __loggers[cacheKey]; |
{ | ||
"name": "debuggo", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "General purpose debug library based on visionmedia/debug", | ||
@@ -37,24 +37,24 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@commitlint/cli": "^8.2.0", | ||
"@commitlint/config-conventional": "^8.2.0", | ||
"@types/chai": "^4.2.4", | ||
"@commitlint/cli": "^8.3.5", | ||
"@commitlint/config-conventional": "^8.3.4", | ||
"@types/chai": "^4.2.11", | ||
"@types/chai-as-promised": "7.1.2", | ||
"@types/chai-spies": "1.0.1", | ||
"@types/debug": "4.1.5", | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.12.7", | ||
"@types/mocha": "^7.0.2", | ||
"@types/node": "^13.11.1", | ||
"chai": "^4.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"chai-spies": "^1.0.0", | ||
"commitizen": "^4.0.3", | ||
"coveralls": "^3.0.7", | ||
"cz-conventional-changelog": "^3.0.2", | ||
"husky": "^3.0.9", | ||
"mocha": "^6.2.2", | ||
"nyc": "^14.1.1", | ||
"rimraf": "^3.0.0", | ||
"semantic-release": "^15.13.30", | ||
"typescript": "^3.7.2" | ||
"commitizen": "^4.0.4", | ||
"coveralls": "^3.0.11", | ||
"cz-conventional-changelog": "^3.1.0", | ||
"husky": "^4.2.5", | ||
"mocha": "^7.1.1", | ||
"nyc": "^15.0.1", | ||
"rimraf": "^3.0.2", | ||
"semantic-release": "^17.0.4", | ||
"typescript": "^3.8.3" | ||
}, | ||
"dependencies": { | ||
"@types/debug": "4.1.5", | ||
"debug": "^4.1.1" | ||
@@ -61,0 +61,0 @@ }, |
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
19
106
7300
2
+ Added@types/debug@4.1.5
+ Added@types/debug@4.1.5(transitive)