chrisbutler / apollo-log

A logging extension for the Apollo GraphQL Server

Home Page:https://shellscape.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Apollo Server

tests cover size

apollo-log

A logging extension for the Apollo GraphQL Server

Please consider donating if you find this project useful.

apollo-server doesn't ship with any comprehensive logging, and instead offloads that responsiblity to the users and the resolvers or context handler. That can be inconvenient. This module provides uniform logging for the entire GraphQL request lifecycle, as provided by extension hooks in apollo-server. The console/terminal result of which will resemble the image below:

Requirements

apollo-log is an evergreen 🌲 module.

This module requires an Active LTS Node version (v10.0.0+).

Install

Using npm:

npm install apollo-log

Usage

Setting up apollo-log is straight-forward. Instantiate the extension, passing any desired options, and pass the extensions array to apollo-server.

const { ApolloLogExtension } = require('apollo-log');
const { ApolloServer } = require('apollo-server');

const options = { ... };
const extensions = [() => new ApolloLogExtension(options)];
const apollo = new ApolloServer({
  extensions,
  ...
});

Options

level

Type: String
Default: info

Specifies at which base level that log messages will be shown (typically info or debug). For more information please see the loglevelnext documentation.

mutate

Type: Function Default: (level, data) => {}

If specified, allows inspecting and mutating the data logged to the console for each message. The level parameter is one of info or debug.

prefix

Type: String
Default: apollo:

Specifies a prefix, colored by level, prepended to each log message.

timestamp

Type: Boolean

If true, will prepend a timestamp in the HH:mm:ss format to each log message.

Meta

CONTRIBUTING

LICENSE (Mozilla Public License)

About

A logging extension for the Apollo GraphQL Server

https://shellscape.org

License:Mozilla Public License 2.0


Languages

Language:JavaScript 100.0%