forked from mirrors/probot
refactor: `getLog(level)` -> `getLog({ level })`
This commit is contained in:
parent
7c46218da8
commit
f50f68f485
|
@ -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.`
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -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'
|
||||
|
@ -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);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
@ -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 })!;
|
||||
|
|
Loading…
Reference in New Issue