Merged in feature/wrap-logging (pull request #2511)

Feature/wrap logging

* feat: change all logging to go through our own logger function so that we can control log levels

* move packages/trpc to using our own logger

* merge


Approved-by: Linus Flood
This commit is contained in:
Joakim Jäderberg
2025-07-03 12:37:04 +00:00
parent 7e32ed294d
commit daf765f3d5
110 changed files with 681 additions and 441 deletions

View File

@@ -3,6 +3,7 @@ import "server-only"
import { ClientError, type GraphQLClient } from "graphql-request"
import { Lang } from "@scandic-hotels/common/constants/language"
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
import { env } from "../../env/server"
@@ -10,6 +11,7 @@ import type { DocumentNode } from "graphql"
import type { Data } from "../types/requestData"
const requestLogger = createLogger("graphql-request")
export async function request<T>(
client: GraphQLClient,
query: string | DocumentNode,
@@ -41,13 +43,9 @@ export async function request<T>(
/**
* TODO: Send to Monitoring (Logging and Metrics)
*/
console.log({
requestLogger.debug("complexity", {
complexityLimit: rawResponse.headers.get("x-query-complexity"),
})
console.log({
referenceDepth: rawResponse.headers.get("x-reference-depth"),
})
console.log({
resolverCost: rawResponse.headers.get("x-resolver-cost"),
})
@@ -63,17 +61,17 @@ export async function request<T>(
// @ts-expect-error: name does not exist (?)
).name.value
console.log(`[gql] Sending graphql request to ${env.CMS_URL}`, {
requestLogger.debug(`[gql] Sending graphql request to ${env.CMS_URL}`, {
operationName,
variables,
})
} catch (e) {
console.error(`[gql] Unable to extract operation name from query`, {
requestLogger.error(`[gql] Unable to extract operation name from query`, {
query,
error: e,
})
console.log(`[gql] Sending graphql request to ${env.CMS_URL}`, {
requestLogger.debug(`[gql] Sending graphql request to ${env.CMS_URL}`, {
operationName: "<Unable to extract>",
variables,
})
@@ -94,18 +92,18 @@ export async function request<T>(
// @ts-expect-error: name does not exist (?)
).name.value
console.log(`[gql] Response for ${env.CMS_URL}`, {
requestLogger.debug(`[gql] Response for ${env.CMS_URL}`, {
response,
operationName,
variables,
})
} catch (e) {
console.error(`[gql] Unable to extract operation name from query`, {
requestLogger.error(`[gql] Unable to extract operation name from query`, {
query,
error: e,
})
console.log(`[gql] Response for ${env.CMS_URL}`, {
requestLogger.debug(`[gql] Response for ${env.CMS_URL}`, {
response,
operationName: "<Unable to extract>",
variables,
@@ -138,7 +136,7 @@ export async function request<T>(
}
}
console.error(
requestLogger.error(
`[gql] Error sending graphql request to ${env.CMS_URL}`,
error
)