graphql-hive / gateway

GraphQL gateway that can act as a Federation Gateway or a Proxy Gateway for any GraphQL service.
https://the-guild.dev/graphql/hive/docs/gateway
MIT License
7 stars 1 forks source link

Question: Custom logger #3

Open fauna5 opened 1 month ago

fauna5 commented 1 month ago

Hi, I need to log in JSON format so i've created a custom logger but am having some issues

export const gatewayConfig = defineConfig({
  ...
  logging: createJsonLogger("customLogger"),
  ...
});

1. Still some plain log lines

This works as expected but i still get some plain log lines as they don't seem to use the logger interface.

[2024-09-24T12:39:25.492Z] INFO   Loaded config
[2024-09-24T12:39:26.474Z] INFO  Worker graphql-hive/platform#2 Serving supergraph from config
[2024-09-24T12:39:26.477Z] INFO  Worker graphql-hive/platform#1 Serving supergraph from config
[2024-09-24T12:39:26.485Z] INFO  Worker graphql-hive/platform#2 Listening on http://localhost:4000
[2024-09-24T12:39:26.488Z] INFO  Worker graphql-hive/platform#1 Listening on http://localhost:4000

2. Worker thread

I like the worker id (Worker graphql-hive/platform#2 above) and i would like to log it in my custom logger. But worker id is not in the context object AFAICS. Is there a way i can access it in my GatewayPlugin?

gateway v1.0.4

ardatan commented 2 days ago

This works as expected but i still get some plain log lines as they don't seem to use the logger interface.

What do you mean by plain log lines? Can you explain it a bit more? What do you expect, and what do you get instead?

Is there a way i can access it in my GatewayPlugin?

It is not part of the runtime. It is CLI that creates workers. We get those IDs from process.worker.id. So you can use the same.