Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(logging): allow pino to be configured #97

Merged
merged 3 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from './types';
export {Changes} from './types';
import {Octokit} from '@octokit/rest';
import {Logger} from 'pino';
import {Logger, LoggerOptions} from 'pino';
import {logger, setupLogger} from './logger';
import {addPullRequestDefaults} from './default-options-handler';
import * as retry from 'async-retry';
Expand Down Expand Up @@ -55,7 +55,7 @@ async function createPullRequest(
octokit: Octokit,
changes: Changes | null | undefined,
options: CreatePullRequestUserOptions,
loggerOption?: Logger
loggerOption?: Logger | LoggerOptions
): Promise<number> {
setupLogger(loggerOption);
// if null undefined, or the empty map then no changes have been provided.
Expand Down
8 changes: 6 additions & 2 deletions src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ import {Logger, Level} from 'pino';
import * as Pino from 'pino';
let logger: Logger;

function setupLogger(userLogger: Logger = Pino()) {
logger = userLogger;
function setupLogger(userLogger?: Logger | Pino.LoggerOptions) {
if (typeof userLogger === 'undefined' || typeof userLogger === 'object') {
logger = Pino(userLogger);
} else {
logger = userLogger as Logger;
}
}

export {logger, Logger, Level, setupLogger};