Skip to content

Latest commit

 

History

History
76 lines (56 loc) · 2.27 KB

README.md

File metadata and controls

76 lines (56 loc) · 2.27 KB

plugin-request-log.js

Log all requests and request errors

@latest Build Status

Usage

Browsers

Load @octokit/plugin-request-log and @octokit/core (or core-compatible module) directly from esm.sh

<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 npm install @octokit/core @octokit/plugin-request-log. Optionally replace @octokit/core with a core-compatible module

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",
  }),
});

Contributing

See CONTRIBUTING.md

License

MIT