Skip to content

Commit

Permalink
feat: use pino for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jan 22, 2021
1 parent 4b97453 commit bcc3554
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@ const { Octokit: OctokitCore } = require("@octokit/core");
const { paginateRest } = require("@octokit/plugin-paginate-rest");
const { throttling } = require("@octokit/plugin-throttling");
const { retry } = require("@octokit/plugin-retry");
const pino = require("pino");

const { cache: octokitCachePlugin } = require("./lib/octokit-plugin-cache");
const { resolveRepositories } = require("./lib/resolve-repositories");
const { name, version } = require("./package.json");

const logger = pino();
const Octokit = OctokitCore.plugin(paginateRest, throttling, retry).defaults({
log: console,
log: {
debug: logger.debug.bind(logger),
info: logger.info.bind(logger),
warn: logger.warn.bind(logger),
error: logger.error.bind(logger),
},
userAgent: [name, version].join("/"),
throttle: {
onAbuseLimit: (error, options) => {
onAbuseLimit: (error, options, octokit) => {
octokit.log.error("onAbuseLimit", error, options);
},
onRateLimit: (error, options) => {
onRateLimit: (error, options, octokit) => {
octokit.log.error("onRateLimit", error, options);
},
},
Expand Down Expand Up @@ -69,9 +76,9 @@ async function octoherd(
const repositories = await resolveRepositories(state, repos);

for (const repository of repositories) {
console.log("Running %s on %s...", script, repository.full_name);
octokit.log.info("Running %s on %s...", script, repository.full_name);
await userScript(octokit, repository, userOptions);
}

console.log("\ndone.");
octokit.log.info("done");
}
54 changes: 53 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@octokit/plugin-throttling": "^3.3.0",
"jsonfile": "^6.0.1",
"mkdirp": "^1.0.4",
"pino": "^6.10.0",
"yargs": "^15.4.1"
},
"devDependencies": {
Expand Down

0 comments on commit bcc3554

Please sign in to comment.