Skip to content

Commit 19954c8

Browse files
authored
feat: allow custom logger for Octokit instances (#2100)
Allow custom logger for Octokit instances
1 parent 89fdd54 commit 19954c8

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/auth.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Logger } from "pino";
12
import { getAuthenticatedOctokit } from "./octokit/get-authenticated-octokit.js";
23
import { ProbotOctokit } from "./octokit/probot-octokit.js";
34
import type { State } from "./types.js";
@@ -31,6 +32,7 @@ import type { State } from "./types.js";
3132
export async function auth(
3233
state: State,
3334
installationId?: number,
35+
log?: Logger,
3436
): Promise<InstanceType<typeof ProbotOctokit>> {
35-
return getAuthenticatedOctokit(Object.assign({}, state), installationId);
37+
return getAuthenticatedOctokit(Object.assign({}, state), installationId, log);
3638
}

src/octokit/get-authenticated-octokit.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { State } from "../types.js";
22
import type { ProbotOctokit } from "./probot-octokit.js";
33
import type { OctokitOptions } from "../types.js";
4-
import type { LogFn, Level } from "pino";
4+
import type { LogFn, Level, Logger } from "pino";
55

66
type FactoryOptions = {
77
octokit: ProbotOctokit;
@@ -12,16 +12,17 @@ type FactoryOptions = {
1212
export async function getAuthenticatedOctokit(
1313
state: State,
1414
installationId?: number,
15+
log?: Logger,
1516
) {
16-
const { log, octokit } = state;
17+
const { octokit } = state;
1718

1819
if (!installationId) return octokit;
1920

2021
return octokit.auth({
2122
type: "installation",
2223
installationId,
2324
factory: ({ octokit, octokitOptions, ...otherOptions }: FactoryOptions) => {
24-
const pinoLog = log.child({ name: "github" });
25+
const pinoLog = log || state.log.child({ name: "github" });
2526

2627
const options: ConstructorParameters<typeof ProbotOctokit>[0] & {
2728
log: Record<Level, LogFn>;

0 commit comments

Comments
 (0)