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:
apollo-log is an evergreen 🌲 module.
This module requires an Active LTS Node version (v10.0.0+).
Using npm:
npm install apollo-logSetting 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,
...
});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.
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.
Type: String
Default: apollo:
Specifies a prefix, colored by level, prepended to each log message.
Type: Boolean
If true, will prepend a timestamp in the HH:mm:ss format to each log message.