@@ -22,6 +22,32 @@ const noop = () => {};
22
22
const consoleWarn = console . warn . bind ( console ) ;
23
23
const consoleError = console . error . bind ( console ) ;
24
24
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
+
25
51
const userAgentTrail = `octokit-core.js/${ VERSION } ${ getUserAgent ( ) } ` ;
26
52
27
53
// Utility to omit a key and still keep dynamic properties
@@ -122,15 +148,7 @@ export class Octokit {
122
148
123
149
this . request = request . defaults ( requestDefaults ) ;
124
150
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 ) ;
134
152
this . hook = hook ;
135
153
136
154
// (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance
0 commit comments