Log all requests and request errors
Browsers |
Load <script type="module">
import { Octokit } from "https://esm.sh/@octokit/core";
import { requestLog } from "https://esm.sh/@octokit/plugin-request-log";
</script> |
---|---|
Node |
Install with import { Octokit } from "@octokit/core";
import { requestLog } from "@octokit/plugin-request-log"; |
Important
As we use conditional exports, you will need to adapt your tsconfig.json
by setting "moduleResolution": "node16", "module": "node16"
.
See the TypeScript docs on package.json "exports".
See this helpful guide on transitioning to ESM from @sindresorhus
const MyOctokit = Octokit.plugin(requestLog);
const octokit = new MyOctokit({ auth: "secret123" });
octokit.request("GET /");
// logs "GET / - 200 in 123ms
octokit.request("GET /oops");
// logs "GET / - 404 in 123ms
In order to log all request options, the log.debug
option needs to be set. We recommend the console-log-level package for a configurable log level
import consoleLogLevel from "console-log-level";
const octokit = new MyOctokit({
log: consoleLogLevel({
auth: "secret123",
level: "info",
}),
});
See CONTRIBUTING.md