Comparing version 7.0.2 to 7.0.3
@@ -12,2 +12,3 @@ "use strict"; | ||
const constants_1 = require("../constants"); | ||
let loggedWarning = false; | ||
const globalThis = globalthis_1.default(); | ||
@@ -107,2 +108,15 @@ const getAsyncLocalContext = () => { | ||
if (!asyncLocalStorage) { | ||
if (loggedWarning === false) { | ||
loggedWarning = true; | ||
onMessage({ | ||
context: { | ||
logLevel: constants_1.logLevels.warn, | ||
package: 'roarr', | ||
}, | ||
message: 'async_hooks are unavailable; Roarr.child will not function as expected', | ||
sequence: getSequence(), | ||
time: Date.now(), | ||
version: config_1.ROARR_LOG_FORMAT_VERSION, | ||
}); | ||
} | ||
return routine(); | ||
@@ -109,0 +123,0 @@ } |
@@ -35,9 +35,7 @@ "use strict"; | ||
}; | ||
// eslint-disable-next-line no-empty | ||
} | ||
catch (_a) { | ||
// eslint-disable-next-line no-console | ||
console.warn('async_hooks are unavailable; Roarr.child will not function as expected'); | ||
} | ||
catch (_a) { } | ||
} | ||
return newState; | ||
}; |
@@ -30,2 +30,29 @@ "use strict"; | ||
}; | ||
ava_1.serial('warns if async_hooks are unavailable', async (t) => { | ||
const firstLog = createLoggerWithHistory(); | ||
const log = firstLog.child({ | ||
// Ensure that we are not adding context to the internal warning. | ||
foo: 'bar', | ||
}); | ||
globalThis.ROARR.asyncLocalStorage = null; | ||
await log.adopt( | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
() => { }); | ||
// Ensure that we log only once. | ||
await log.adopt( | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
() => { }); | ||
t.deepEqual(firstLog.messages, [ | ||
{ | ||
context: { | ||
logLevel: 40, | ||
package: 'roarr', | ||
}, | ||
message: 'async_hooks are unavailable; Roarr.child will not function as expected', | ||
sequence: '0', | ||
time, | ||
version, | ||
}, | ||
]); | ||
}); | ||
ava_1.serial('inherits context from async local scope', async (t) => { | ||
@@ -32,0 +59,0 @@ const log = createLoggerWithHistory(); |
@@ -81,3 +81,3 @@ { | ||
"typings": "./dist/src/Roarr.d.ts", | ||
"version": "7.0.2" | ||
"version": "7.0.3" | ||
} |
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
66555
1287