Skip to content

Commit

Permalink
refactor: getLog(level) -> getLog({ level })
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Nov 20, 2020
1 parent 7c46218 commit f50f68f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export class Application {
private internalRouter: Router;

constructor(options: Options) {
this.log = aliasLog(options.log || getLog(process.env.LOG_LEVEL));
this.log = aliasLog(
options.log || getLog({ level: process.env.LOG_LEVEL })
);

this.log.warn(
`[probot] "import { Application } from 'probot'" is deprecated. Use "import { Probot } from 'probot'" instead, the APIs are the same.`
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/get-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import pino from "pino";
import type { LoggerOptions } from "pino";
import { getTransformStream } from "@probot/pino";

export function getLog(level: string = "info") {
type Options = {
level?: string;
};

export function getLog({ level }: Options = { level: "info" }) {
const pinoOptions: LoggerOptions = { level, name: "probot" };
const transform = getTransformStream();
transform.pipe(pino.destination(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getLog } from "./get-log";

export function logWarningsForObsoleteEnvironmentVariables() {
const log = getLog(process.env.LOG_LEVEL);
const log = getLog({ level: process.env.LOG_LEVEL });

// TODO: remove deprecation warning in v11
if ("DISABLE_STATS" in process.env) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ProbotOctokit } from "./octokit/probot-octokit";
import { run } from "./run";

export const createProbot = (options: Options) => {
options.log = options.log || getLog(process.env.LOG_LEVEL);
options.log = options.log || getLog({ level: process.env.LOG_LEVEL });
options.log.warn(
new Deprecation(
`[probot] "createProbot(options)" is deprecated, use "new Probot(options)" instead`
Expand Down
4 changes: 2 additions & 2 deletions src/probot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const defaultAppFns: ApplicationFunction[] = [defaultApp];

export class Probot {
public static async run(appFn: ApplicationFunction | string[]) {
const log = getLog(process.env.LOG_LEVEL);
const log = getLog({ level: process.env.LOG_LEVEL });
log.warn(
new Deprecation(
'[probot] "Probot.run" is deprecate. Import { run } from "probot" instead'
Expand Down Expand Up @@ -112,7 +112,7 @@ export class Probot {
level = process.env.LOG_LEVEL as Options["logLevel"];
}

this.log = aliasLog(options.log || getLog(level));
this.log = aliasLog(options.log || getLog({ level }));

if (logEnvVariableDeprecation) {
this.log.warn(logEnvVariableDeprecation);
Expand Down
2 changes: 1 addition & 1 deletion test/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("server", () => {

beforeEach(() => {
webhook = jest.fn((req, res, next) => next());
server = createServer({ webhook, logger: getLog("fatal") });
server = createServer({ webhook, logger: getLog({ level: "fatal" }) });

// Error handler to avoid printing logs
server.use(
Expand Down
4 changes: 2 additions & 2 deletions test/webhook-proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("webhook-proxy", () => {
url,
port: targetPort,
path: "/test",
logger: getLog("fatal"),
logger: getLog({ level: "fatal" }),
})!;

// Wait for proxy to be ready
Expand Down Expand Up @@ -74,7 +74,7 @@ describe("webhook-proxy", () => {
const url = "http://bad.proxy/events";
nock("http://bad.proxy").get("/events").reply(404);

const log = getLog("fatal").child({});
const log = getLog({ level: "fatal" }).child({});
log.error = jest.fn();

proxy = createWebhookProxy({ url, logger: log })!;
Expand Down

0 comments on commit f50f68f

Please sign in to comment.