apollographql / apollo-server

🌍  Spec-compliant and production ready JavaScript GraphQL server that lets you develop in a schema-first way. Built for Express, Connect, Hapi, Koa, and more.
https://www.apollographql.com/docs/apollo-server/
MIT License
13.77k stars 2.03k forks source link

console logging is inadequate for a production server #1264

Closed brandondoran closed 6 years ago

brandondoran commented 6 years ago

Apollo Server claims to be "production-ready" but I would not consider using console for logging as production quality. The project should provide the ability to use a custom logger such as bunyan, winston, pino, etc to allow for basic features, like log levels and formatting, that you need in a real production app. When logs have a well defined format, such as json, they can be sent to a kibana/splunk, etc for introspection

I'm using apollo-server in production now and most logs are taken care of in user code. But I would imagine in 2.0, with the apollo-datasource-rest, there will be many more scenarios where apollo-server itself will need to log, such as http error details, response times.

My specific use case is that I want to be able to use the same logger in apollo-server as I do in application code so that the format is the same and to allow trace or debug logs to be seen in dev but not clutter up production logs by using log levels instead of conditional code based on NODE_ENV like here. Maybe I want to temporarily see debug logs in production to troubleshoot and issue, which in a 12 Factor app, I should able to do but just changing log level config, not modifying code.

I'd be more than happy to help out here.

evans commented 6 years ago

@brandondoran Thank you for bringing up the concern! Here are the docs for metrics/logging https://www.apollographql.com/docs/apollo-server/v2/features/metrics.html#Logging. If you would like to add more to those docs, that would be extremely valuable.

The next thing on my list is documenting the extensions api, which you can do things like: https://github.com/apollographql/apollo-server/blob/8914b135df9840051fe81cc9224b444cfc5b61ab/packages/apollo-server-core/src/logging.ts. Are you looking for more functionality than that? Adding more to extensions would also be a great contribution.

The rest data source is a relatively new portion of the stack, so we'll be adding tracing support soon after the 2.0 launch. If you're looking for something specific, we'd love to hear it!

brandondoran commented 6 years ago

@evans Thanks for the links! I'm not running v2 yet so I haven't looked at this part of the docs in detail. Once I start getting my hands dirty with it, I'll keep in mind contributing to the docs if it seems lacking.

shellscape commented 5 years ago

I'm in agreement with the OP. Additionally, documentation on how to write an extension (let alone one without being forced into TypeScript) is non-existent. @evans we're fast approaching a year since you mentioned that the extensions need to be documented. This is a major hole in entire platform.

ngbrown commented 5 years ago

I've been using a logging extension that I made which integrates with bunyan. Feel free to use it as as starting point your logger:

https://gist.github.com/ngbrown/b626c589b76d0f6ef6f9801a2faf6458

shellscape commented 5 years ago

I've secured apollo-log on npm and will be releasing a leveled logger for apollo-server in the coming weeks. Still mind boggling that this is a need, but alas.