Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature requests: custom logger class for gateway/server/etc #3467

Closed
nurdism opened this issue Nov 3, 2019 · 2 comments
Closed

Feature requests: custom logger class for gateway/server/etc #3467

nurdism opened this issue Nov 3, 2019 · 2 comments

Comments

@nurdism
Copy link

nurdism commented Nov 3, 2019

I'm currently using fastify with apollo-server & apollo-gateway, I'd like to unify the loggers as there are several parts of my app that implement their own logging, I'd like to be able to pass my own logging class to the gateway to use for logging.

@eliw00d
Copy link

eliw00d commented Mar 26, 2020

This would be very useful for apollo-gateway when using apollo-server plugins with a specific logger to keep logging consistent.

@abernix abernix added this to the Release 2.12.0 milestone Mar 26, 2020
@abernix
Copy link
Member

abernix commented Mar 26, 2020

This feature recently landed with #3894, including the possibility to access the logger provided to Apollo Server from plugins. This is currently published on the next npm tag and can be installed with npm install <package>@next for either apollo-server-* or @apollo/gateway.

Since server and gateway are (currently) instantiated separately, for the time-being, it will still be necessary to pass the logger to both ApolloServer and ApolloGateway during their setup. The one made available to Apollo Server will be on the request context, for both RemoteGraphQLDataSources and for plugins. The logger passed to ApolloGateway will be used for non-request specific logging. Roughly, though I haven't tested this, it should work as such:

const logger = console; // Needs `debug`, `info`, `warn` and `error`.

const gateway = new ApolloGateway({
  logger,
});

const server = new ApolloServer({
  logger,
  gateway,
  plugins: [
    requestDidStart({ logger }) {
      logger.warn("Your own message from your own plugin!");
    }
  ],
});

@abernix abernix closed this as completed Mar 26, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants