Skip to content

Commit

Permalink
feat: probot.log. probot.logger is now deprecated (#1301)
Browse files Browse the repository at this point in the history
* refactor: remove types for obsolete `promise-events` package

* test: `probot.log`. `probot.logger` is now deprecated

* feat: `probot.log`. `probot.logger` is now deprecated
  • Loading branch information
gr2m committed Aug 12, 2020
1 parent b7713bf commit 2bacd14
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
9 changes: 0 additions & 9 deletions src/@types/promise-events/index.d.ts

This file was deleted.

42 changes: 27 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class Probot {

public server: express.Application;
public webhooks: ProbotWebhooks;
public logger: Logger;
public log: Logger;

// These 3 need to be public for the tests to work.
public options: Options;
Expand All @@ -151,6 +151,18 @@ export class Probot {
private apps: Application[];
private state: State;

/**
* @deprecated use probot.log instead
*/
public get logger() {
this.log.warn(
new Deprecation(
`[probot] "probot.logger" is deprecated. Use "probot.log" instead`
)
);
return this.log;
}

constructor(options: Options) {
if (process.env.GHE_HOST && /^https?:\/\//.test(process.env.GHE_HOST)) {
throw new Error(
Expand All @@ -164,11 +176,11 @@ export class Probot {
options.webhookPath = options.webhookPath || "/";
options.secret = options.secret || "development";

// TODO: deprecate probot.logger in favor of probot.log.
this.logger = options.log || getLog();
// TODO: deprecate probot.log in favor of probot.log.
this.log = options.log || getLog();

if (options.cert) {
this.logger.warn(
this.log.warn(
new Deprecation(
`[probot] "cert" option is deprecated. Use "privateKey" instead`
)
Expand Down Expand Up @@ -199,14 +211,14 @@ export class Probot {
const octokit = new Octokit();

this.throttleOptions = getThrottleOptions({
log: this.logger,
log: this.log,
redisConfig: options.redisConfig,
});

this.state = {
cache,
githubToken: options.githubToken,
log: this.logger,
log: this.log,
Octokit,
octokit,
throttleOptions: this.throttleOptions,
Expand All @@ -218,19 +230,19 @@ export class Probot {
transform: webhookTransform.bind(null, this.state),
});
// TODO: normalize error handler with code in application.ts
this.webhooks.on("error", getErrorHandler(this.logger));
this.webhooks.on("error", getErrorHandler(this.log));

this.server = createServer({
webhook: (this.webhooks as any).middleware,
logger: this.logger,
logger: this.log,
});
}

/**
* @deprecated `probot.webhook` is deprecated. Use `probot.webhooks` instead
*/
public get webhook(): Webhooks {
this.logger.warn(
this.log.warn(
new Deprecation(
`[probot] "probot.webhook" is deprecated. Use "probot.webhooks" instead instead`
)
Expand All @@ -240,7 +252,7 @@ export class Probot {
}

public receive(event: WebhookEvent) {
this.logger.debug({ event }, "Webhook received");
this.log.debug({ event }, "Webhook received");
return Promise.all(this.apps.map((app) => app.receive(event)));
}

Expand Down Expand Up @@ -278,7 +290,7 @@ export class Probot {
// Register error handler as the last middleware
this.server.use(
pinoHttp({
logger: this.logger,
logger: this.log,
})
);
}
Expand All @@ -288,21 +300,21 @@ export class Probot {
.listen(this.options.port, () => {
if (this.options.webhookProxy) {
createWebhookProxy({
logger: this.logger,
logger: this.log,
path: this.options.webhookPath,
port: this.options.port,
url: this.options.webhookProxy,
});
}
this.logger.info("Listening on http://localhost:" + this.options.port);
this.log.info("Listening on http://localhost:" + this.options.port);
})
.on("error", (err: NodeJS.ErrnoException) => {
if (err.code === "EADDRINUSE") {
this.logger.error(
this.log.error(
`Port ${this.options.port} is already in use. You can define the PORT environment variable to use a different port.`
);
} else {
this.logger.error(err);
this.log.error(err);
}
process.exit(1);
});
Expand Down
10 changes: 10 additions & 0 deletions test/deprecations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,14 @@ describe("Deprecations", () => {
`[probot] "cert" option is deprecated. Use "privateKey" instead`
);
});

it("probot.logger", () => {
const probot = new Probot({ log: pino(streamLogsToOutput) });
probot.logger.info("test");

expect(output.length).toEqual(2);
expect(output[0].msg).toContain(
`[probot] "probot.logger" is deprecated. Use "probot.log" instead`
);
});
});

0 comments on commit 2bacd14

Please sign in to comment.