kriasoft / graphql-starter-kit

💥 Monorepo template (seed project) pre-configured with GraphQL API, PostgreSQL, React, and Joy UI.
https://graphqlstart.com
MIT License
3.88k stars 553 forks source link

[`api`] Logging and error reporting #318

Closed koistya closed 2 years ago

koistya commented 2 years ago

Usage Example

From within the GraphQL type resolvers:

{
  type: UserType,
  resolve(self, args, ctx) {
    ctx.log("INFO", "Fetching user account.");

    try {
      /* .... */
    } catch (err) {
      ctx.log("ERROR", err);
    }
  }
}

Or, from anywhere within the Node.js/Express app:

import { log } from "./core";

app.get("/example", (req, res) => {
  log(req, res, "INFO", "Hello from Express app.");
  ...
});

Reference https://cloud.google.com/functions/docs/monitoring/logging