Skip to content

Commit 1564400

Browse files
Uzlopakwolfy1339
authored andcommitted
fix: dont lose this reference for loggers (#708)
1 parent 49e6fed commit 1564400

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,17 @@ export function createAppAuth(options: StrategyOptions): AuthInterface {
4545
);
4646
}
4747

48-
const log = Object.assign(
49-
{
50-
warn: console.warn.bind(console),
51-
},
52-
options.log,
53-
);
48+
/**
49+
* Mutate the logger to ensure it has a `warn` method.
50+
*
51+
* Some Loggers like pino need that the `this` reference points
52+
* to the original object, so we cannot use `Object.assign` here.
53+
*/
54+
const log = options.log || ({} as NonNullable<StrategyOptions["log"]>);
55+
if (typeof log.warn !== "function") {
56+
log.warn = console.warn.bind(console);
57+
}
58+
5459
const request =
5560
options.request ||
5661
defaultRequest.defaults({

0 commit comments

Comments
 (0)