Comparing version
@@ -25,3 +25,3 @@ /// <reference types="node" /> | ||
export declare type Logger = LogMethod & { | ||
adopt: <T>(routine: () => Promise<T>, context: MessageContext) => Promise<T>; | ||
adopt: <T>(routine: () => T, context?: MessageContext) => Promise<T>; | ||
child: (context: MessageContext | TranslateMessageFunction) => Logger; | ||
@@ -28,0 +28,0 @@ debug: LogMethod; |
"use strict"; | ||
/* eslint-disable max-nested-callbacks */ | ||
/* eslint-disable ava/use-test */ | ||
@@ -122,6 +123,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
const log = createLoggerWithHistory(); | ||
log.adopt(() => { | ||
void log.adopt(() => { | ||
log('foo'); | ||
}); | ||
log.adopt(() => { | ||
void log.adopt(() => { | ||
log('bar'); | ||
@@ -146,9 +147,34 @@ }); | ||
}); | ||
(0, ava_1.serial)('top-level adopt increments global sequence (async)', async (t) => { | ||
const log = createLoggerWithHistory(); | ||
void log.adopt(async () => { | ||
log('foo'); | ||
}); | ||
void log.adopt(async () => { | ||
log('bar'); | ||
}); | ||
t.deepEqual(log.messages, [ | ||
{ | ||
context: {}, | ||
message: 'foo', | ||
sequence: '0.0', | ||
time, | ||
version, | ||
}, | ||
{ | ||
context: {}, | ||
message: 'bar', | ||
sequence: '1.0', | ||
time, | ||
version, | ||
}, | ||
]); | ||
}); | ||
(0, ava_1.serial)('logs within adopt increment local sequence', async (t) => { | ||
const log = createLoggerWithHistory(); | ||
log.adopt(() => { | ||
void log.adopt(() => { | ||
log('foo'); | ||
log('bar'); | ||
}); | ||
log.adopt(() => { | ||
void log.adopt(() => { | ||
log('baz'); | ||
@@ -188,7 +214,48 @@ log('qux'); | ||
}); | ||
(0, ava_1.serial)('logs within adopt increment local sequence (async)', async (t) => { | ||
const log = createLoggerWithHistory(); | ||
void log.adopt(async () => { | ||
log('foo'); | ||
log('bar'); | ||
}); | ||
void log.adopt(async () => { | ||
log('baz'); | ||
log('qux'); | ||
}); | ||
t.deepEqual(log.messages, [ | ||
{ | ||
context: {}, | ||
message: 'foo', | ||
sequence: '0.0', | ||
time, | ||
version, | ||
}, | ||
{ | ||
context: {}, | ||
message: 'bar', | ||
sequence: '0.1', | ||
time, | ||
version, | ||
}, | ||
{ | ||
context: {}, | ||
message: 'baz', | ||
sequence: '1.0', | ||
time, | ||
version, | ||
}, | ||
{ | ||
context: {}, | ||
message: 'qux', | ||
sequence: '1.1', | ||
time, | ||
version, | ||
}, | ||
]); | ||
}); | ||
(0, ava_1.serial)('nested adopt increment local sequence', async (t) => { | ||
const log = createLoggerWithHistory(); | ||
log.adopt(() => { | ||
void log.adopt(() => { | ||
log('foo'); | ||
log.adopt(() => { | ||
void log.adopt(() => { | ||
log('bar'); | ||
@@ -214,7 +281,32 @@ }); | ||
}); | ||
(0, ava_1.serial)('nested adopt increment local sequence (async)', async (t) => { | ||
const log = createLoggerWithHistory(); | ||
void log.adopt(async () => { | ||
log('foo'); | ||
await log.adopt(async () => { | ||
log('bar'); | ||
}); | ||
}); | ||
t.deepEqual(log.messages, [ | ||
{ | ||
context: {}, | ||
message: 'foo', | ||
sequence: '0.0', | ||
time, | ||
version, | ||
}, | ||
{ | ||
context: {}, | ||
message: 'bar', | ||
sequence: '0.1.0', | ||
time, | ||
version, | ||
}, | ||
]); | ||
}); | ||
(0, ava_1.serial)('adopted scope maintains reference to local sequence', async (t) => { | ||
const log = createLoggerWithHistory(); | ||
log.adopt(() => { | ||
void log.adopt(() => { | ||
log('foo'); | ||
log.adopt(() => { | ||
void log.adopt(() => { | ||
log('bar 0'); | ||
@@ -266,7 +358,7 @@ log('bar 1'); | ||
const log = createLoggerWithHistory(); | ||
log.adopt(() => { | ||
void log.adopt(() => { | ||
log('foo 0'); | ||
log.adopt(() => { | ||
void log.adopt(() => { | ||
log('bar 0'); | ||
log.adopt(() => { | ||
void log.adopt(() => { | ||
log('baz 0'); | ||
@@ -273,0 +365,0 @@ setTimeout(() => { |
@@ -76,3 +76,3 @@ { | ||
"typings": "./dist/src/Roarr.d.ts", | ||
"version": "7.4.0" | ||
"version": "7.4.1" | ||
} |
@@ -162,2 +162,4 @@ <a name="roarr"></a> | ||
You may also use [`@roarr/browser-log-writer`](https://github.com/gajus/roarr-browser-log-writer) that implements and opinionated browser logger with [Liqe](https://github.com/gajus/liqe) query support for filtering logs. | ||
<a name="roarr-usage-filtering-logs"></a> | ||
@@ -164,0 +166,0 @@ ### Filtering logs |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
75017
3.3%1494
6.56%775
0.26%