-
Notifications
You must be signed in to change notification settings - Fork 2k
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
docs: logging with a custom logger #4072
Comments
#3894 has more details but you can pass a By default, it uses |
Can you share an example |
const server = new ApolloServer({
logger: console,
}); |
I tried adding options like warn, debug like the examples and documentation but its not working |
Hello, any news on that ? I would like some more examples to understand how to use a custom logger. |
Hello, @abernix any update on how to use options like warn, debug, etc. |
I wrote a small example by adjusting the sample Apollo Server implementation within the README (https://github.com/apollographql/apollo-server#installation-standalone). The sample below will utilize a custom logger (only the debug function) when Apollo Server starts to fulfill a GraphQL request. const { ApolloServer, gql } = require('apollo-server');
// The GraphQL schema
const typeDefs = gql`
type Query {
"A simple type for getting started!"
hello: String
}
`;
// A map of functions which return data for the schema.
const resolvers = {
Query: {
hello: () => 'world',
},
};
const customLogger = {
...console,
debug: (msg) => {
const timestamp = new Date().toISOString();
console.debug(`[${timestamp}] [DEBUG]: ${msg}`);
},
};
const server = new ApolloServer({
typeDefs,
resolvers,
logger: customLogger,
debug: true, // required to output all log levels
plugins: [
{
requestDidStart({ logger }) {
logger.debug('received request');
},
}
],
});
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
}); To run the snippet above:
I utilized a plugin to demonstrate the availability of the logger on the I hope this helps. |
The |
https://github.com/apollographql/apollo-server/blob/80a12d89ea1ae9a0892f4a81d9213eddf95ca965/packages/apollo-server-types/src/index.ts#L114-L121
The text was updated successfully, but these errors were encountered: