@@ -22,6 +22,32 @@ const noop = () => {};
2222const consoleWarn = console . warn . bind ( console ) ;
2323const consoleError = console . error . bind ( console ) ;
2424
25+ /**
26+ * Creates a logger object for the Octokit instance.
27+ *
28+ * If a logger is provided, it will ensure that the logger has
29+ * `debug`, `info`, `warn`, and `error` methods.
30+ * If no logger is provided, it will create a default logger.
31+ *
32+ * Some Loggers like pino need that the this reference point
33+ * to the original object, so we cannot use `Object.assign` here.
34+ */
35+ function createLogger ( logger = { } as NonNullable < OctokitOptions [ "log" ] > ) {
36+ if ( typeof logger . debug !== "function" ) {
37+ logger . debug = noop ;
38+ }
39+ if ( typeof logger . info !== "function" ) {
40+ logger . info = noop ;
41+ }
42+ if ( typeof logger . warn !== "function" ) {
43+ logger . warn = consoleWarn ;
44+ }
45+ if ( typeof logger . error !== "function" ) {
46+ logger . error = consoleError ;
47+ }
48+ return logger as NonNullable < OctokitOptions [ "log" ] > ;
49+ }
50+
2551const userAgentTrail = `octokit-core.js/${ VERSION } ${ getUserAgent ( ) } ` ;
2652
2753// Utility to omit a key and still keep dynamic properties
@@ -122,15 +148,7 @@ export class Octokit {
122148
123149 this . request = request . defaults ( requestDefaults ) ;
124150 this . graphql = withCustomRequest ( this . request ) . defaults ( requestDefaults ) ;
125- this . log = Object . assign (
126- {
127- debug : noop ,
128- info : noop ,
129- warn : consoleWarn ,
130- error : consoleError ,
131- } ,
132- options . log ,
133- ) ;
151+ this . log = createLogger ( options . log ) ;
134152 this . hook = hook ;
135153
136154 // (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance
0 commit comments