Comparing version 1.1.0-beta.4 to 1.1.0-beta.5
@@ -153,8 +153,5 @@ /** | ||
/** | ||
* A mapping of level name `string` to level `number` that consists | ||
* of at least the keys from `logLevels` plus arbitrary other keys | ||
* A mapping of level name `string` to level `number` | ||
*/ | ||
export type LogLevels = typeof logLevels & { | ||
[level: string]: number; | ||
}; | ||
export type LogLevels = typeof logLevels; | ||
/** | ||
@@ -161,0 +158,0 @@ * A default set of level name/value pairs that maps well to the console. |
@@ -27,4 +27,6 @@ var anylogger = (function () { | ||
[name]); | ||
// a default no-op extension | ||
const noop = (logfn) => { | ||
// anylogger.ext extends the given `logger` function | ||
// the implementation here only adds no-ops | ||
// adapters should change this behavior | ||
anylogger.ext = (logfn) => { | ||
logfn.enabledFor = () => { }; | ||
@@ -36,6 +38,2 @@ for (const lvl in anylogger.levels) { | ||
}; | ||
// anylogger.ext extends the given `logger` function | ||
// the implementation here only adds no-ops | ||
// adapters should change this behavior | ||
anylogger.ext = noop; | ||
/** | ||
@@ -52,3 +50,3 @@ * A default set of level name/value pairs that maps well to the console. | ||
// select the level to use | ||
// if multiple args and first matches a level name | ||
// if multiple args and first arg matches a level name | ||
(((args.length > 1) && anylogger.levels[args[0]]) | ||
@@ -55,0 +53,0 @@ ? args.shift() // use the level from the args |
@@ -25,4 +25,6 @@ /** | ||
[name]); | ||
// a default no-op extension | ||
const noop = (logfn) => { | ||
// anylogger.ext extends the given `logger` function | ||
// the implementation here only adds no-ops | ||
// adapters should change this behavior | ||
anylogger.ext = (logfn) => { | ||
logfn.enabledFor = () => { }; | ||
@@ -34,6 +36,2 @@ for (const lvl in anylogger.levels) { | ||
}; | ||
// anylogger.ext extends the given `logger` function | ||
// the implementation here only adds no-ops | ||
// adapters should change this behavior | ||
anylogger.ext = noop; | ||
/** | ||
@@ -50,3 +48,3 @@ * A default set of level name/value pairs that maps well to the console. | ||
// select the level to use | ||
// if multiple args and first matches a level name | ||
// if multiple args and first arg matches a level name | ||
(((args.length > 1) && anylogger.levels[args[0]]) | ||
@@ -53,0 +51,0 @@ ? args.shift() // use the level from the args |
@@ -1,1 +0,1 @@ | ||
var anylogger=function(){const n=e=>n.all[e]||(n.all[e]=n.ext(n.new(e)));n.all=Object.create(null),n.new=l=>({[l]:(...e)=>n.log(l,...e)})[l];n.ext=e=>{e.enabledFor=()=>{};for(const l in n.levels)e[l]=()=>{};return e};return n.levels={error:1,warn:2,info:3,log:4,debug:5,trace:6},n.log=(e,...l)=>n(e)[1<l.length&&n.levels[l[0]]?l.shift():"log"](...l),n}(); | ||
var anylogger=function(){const n=e=>n.all[e]||(n.all[e]=n.ext(n.new(e)));n.all=Object.create(null),n.new=l=>({[l]:(...e)=>n.log(l,...e)})[l],n.ext=e=>{e.enabledFor=()=>{};for(const l in n.levels)e[l]=()=>{};return e};return n.levels={error:1,warn:2,info:3,log:4,debug:5,trace:6},n.log=(e,...l)=>n(e)[1<l.length&&n.levels[l[0]]?l.shift():"log"](...l),n}(); |
@@ -146,7 +146,9 @@ /** | ||
// a default no-op extension | ||
const noop: Extension = (logfn: LogFunction): Logger => { | ||
// anylogger.ext extends the given `logger` function | ||
// the implementation here only adds no-ops | ||
// adapters should change this behavior | ||
anylogger.ext = (logfn) => { | ||
(logfn as Logger).enabledFor = ()=>{} | ||
for (const lvl in anylogger.levels) { | ||
(logfn as Logger)[lvl as LogLevel] = ()=>{} | ||
(logfn as any)[lvl as LogLevel] = ()=>{} | ||
} | ||
@@ -156,7 +158,2 @@ return logfn as Logger | ||
// anylogger.ext extends the given `logger` function | ||
// the implementation here only adds no-ops | ||
// adapters should change this behavior | ||
anylogger.ext = noop | ||
/** | ||
@@ -207,6 +204,5 @@ * An Adapter accepts the `anyLogger` function and optionally | ||
/** | ||
* A mapping of level name `string` to level `number` that consists | ||
* of at least the keys from `logLevels` plus arbitrary other keys | ||
* A mapping of level name `string` to level `number` | ||
*/ | ||
export type LogLevels = typeof logLevels & { [level: string]: number } | ||
export type LogLevels = typeof logLevels | ||
@@ -274,6 +270,6 @@ /** | ||
// select the logger to use | ||
anylogger(name)[ | ||
(anylogger(name) as any)[ | ||
// select the level to use | ||
// if multiple args and first matches a level name | ||
(((args.length > 1) && anylogger.levels[args[0] as LogLevel]) | ||
// if multiple args and first arg matches a level name | ||
(((args.length > 1) && (anylogger as any).levels[args[0] as LogLevel]) | ||
? args.shift() // use the level from the args | ||
@@ -280,0 +276,0 @@ : 'log' // else use default level `'log'` |
{ | ||
"name": "anylogger", | ||
"version": "1.1.0-beta.4", | ||
"version": "1.1.0-beta.5", | ||
"description": "Get a logger. Any logger.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -1,2 +0,2 @@ | ||
# anylogger <sub><sup>1.1.0-beta.4</sup></sub> | ||
# anylogger <sub><sup>1.1.0-beta.5</sup></sub> | ||
### Get a logger. Any logger. | ||
@@ -153,11 +153,11 @@ | ||
* [anylogger.ts](https://unpkg.com/anylogger@1.1.0-beta.4/anylogger.ts) | ||
* [anylogger.ts](https://unpkg.com/anylogger@1.1.0-beta.5/anylogger.ts) | ||
(fully commented source ~7kB) | ||
* [anylogger.d.ts](https://unpkg.com/anylogger@1.1.0-beta.4/anylogger.d.ts) | ||
* [anylogger.d.ts](https://unpkg.com/anylogger@1.1.0-beta.5/anylogger.d.ts) | ||
(typescript type definitions ~6kB) | ||
* [anylogger.js](https://unpkg.com/anylogger@1.1.0-beta.4/anylogger.js) | ||
* [anylogger.js](https://unpkg.com/anylogger@1.1.0-beta.5/anylogger.js) | ||
(javascript esm module ~2kB) | ||
* [anylogger.cjs](https://unpkg.com/anylogger@1.1.0-beta.4/anylogger.cjs) | ||
* [anylogger.cjs](https://unpkg.com/anylogger@1.1.0-beta.5/anylogger.cjs) | ||
(javascript commonjs module ~2kB) | ||
* [anylogger.min.js](https://unpkg.com/anylogger@1.1.0-beta.4/anylogger.min.js) | ||
* [anylogger.min.js](https://unpkg.com/anylogger@1.1.0-beta.5/anylogger.min.js) | ||
(minified 355 bytes, gzipped ~[259](#gzip-size) bytes) | ||
@@ -170,3 +170,3 @@ | ||
```html | ||
<script src="https://unpkg.com/anylogger@1.1.0-beta.4"></script> | ||
<script src="https://unpkg.com/anylogger@1.1.0-beta.5"></script> | ||
<script>(function(){ // IIFE | ||
@@ -671,3 +671,3 @@ var log = anylogger('index.html') | ||
Please have a look at the | ||
[source](https://unpkg.com/anylogger@1.1.0-beta.4/anylogger.js) | ||
[source](https://unpkg.com/anylogger@1.1.0-beta.5/anylogger.js) | ||
it should make it more clear how to write an adapter. Also consider studying | ||
@@ -674,0 +674,0 @@ the [available adapters](https://www.npmjs.com/search?q=keywords:anylogger) |
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
61032
785