What is @octokit/plugin-request-log?
@octokit/plugin-request-log is a plugin for Octokit that logs all requests made to the GitHub API. It is useful for debugging and monitoring the requests your application makes to GitHub.
What are @octokit/plugin-request-log's main functionalities?
Logging Requests
This feature allows you to log all requests made to the GitHub API. The code sample demonstrates how to create an Octokit instance with the requestLog plugin and make a request to the GitHub API, which will be logged.
const { Octokit } = require('@octokit/core');
const { requestLog } = require('@octokit/plugin-request-log');
const MyOctokit = Octokit.plugin(requestLog);
const octokit = new MyOctokit();
async function logRequests() {
await octokit.request('GET /repos/{owner}/{repo}', {
owner: 'octocat',
repo: 'hello-world'
});
}
logRequests();
Custom Log Output
This feature allows you to customize the log output by providing your own logging functions. The code sample demonstrates how to create an Octokit instance with custom log functions and make a request to the GitHub API, which will be logged using the custom functions.
const { Octokit } = require('@octokit/core');
const { requestLog } = require('@octokit/plugin-request-log');
const MyOctokit = Octokit.plugin(requestLog);
const octokit = new MyOctokit({
log: {
debug: console.debug,
info: console.info,
warn: console.warn,
error: console.error
}
});
async function logRequests() {
await octokit.request('GET /repos/{owner}/{repo}', {
owner: 'octocat',
repo: 'hello-world'
});
}
logRequests();
Other packages similar to @octokit/plugin-request-log
axios-debug-log
axios-debug-log is a middleware for Axios that logs request and response details. It is similar to @octokit/plugin-request-log in that it provides logging capabilities for HTTP requests, but it is designed specifically for Axios rather than Octokit.
winston
winston is a versatile logging library for Node.js. While it is not specifically designed for logging HTTP requests, it can be used in conjunction with request libraries to log request and response details. It offers more advanced logging features compared to @octokit/plugin-request-log.
morgan
morgan is an HTTP request logger middleware for Node.js. It is commonly used with Express.js to log incoming HTTP requests. Unlike @octokit/plugin-request-log, which is specific to Octokit and GitHub API requests, morgan is a general-purpose HTTP request logger.
plugin-request-log.js
Log all requests and request errors
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 /");
octokit.request("GET /oops");
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