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

@@ -1,5 +1,6 @@
import { z } from "zod"
import { logger } from "@scandic-hotels/common/logger"
import { toLang } from "@scandic-hotels/common/utils/languages"
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
@@ -115,7 +116,7 @@ function getRate(rate: RateDefinition) {
case "NotCancellable":
return RateEnum.save
default:
console.info(
logger.warn(
`Unknown cancellationRule [${rate.cancellationRule}]. This should never happen!`
)
return null

View File

@@ -1,6 +1,7 @@
import { Lang } from "@scandic-hotels/common/constants/language"
import { getCacheClient } from "@scandic-hotels/common/dataCache"
import { dt } from "@scandic-hotels/common/dt"
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
import { createCounter } from "@scandic-hotels/common/telemetry"
import { env } from "../../../env/server"
@@ -79,6 +80,8 @@ import type {
import type { CityLocation } from "../../types/locations"
import type { Room } from "../../types/room"
const hotelQueryLogger = createLogger("hotelQueryRouter")
export const hotelQueryRouter = router({
availability: router({
hotelsByCity: safeProtectedServiceProcedure
@@ -189,8 +192,10 @@ export const hotelQueryRouter = router({
const selectedRooms = []
for (const [idx, room] of availability.entries()) {
if (!room || "error" in room) {
console.info(`Availability failed: ${room.error}`)
console.error(room.details)
hotelQueryLogger.error(
`Availability failed: ${room.error}`,
room.details
)
selectedRooms.push(null)
continue
}
@@ -203,7 +208,7 @@ export const hotelQueryRouter = router({
ctx.userPoints
)
if (!selected) {
console.error("Unable to find selected room")
hotelQueryLogger.error("Unable to find selected room")
selectedRooms.push(null)
continue
}
@@ -347,7 +352,7 @@ export const hotelQueryRouter = router({
)
if (!selected) {
console.error("Unable to find selected room")
hotelQueryLogger.error("Unable to find selected room")
return null
}
@@ -895,13 +900,13 @@ export const hotelQueryRouter = router({
const data = await response.json()
if (data.status !== "OK") {
console.error(`Geocode error: ${data.status}`)
hotelQueryLogger.error(`Geocode error: ${data.status}`)
return null
}
const location = data.results[0]?.geometry?.location
if (!location) {
console.error("No location found in geocode response")
hotelQueryLogger.error("No location found in geocode response")
return null
}

View File

@@ -4,6 +4,7 @@ import stringify from "json-stable-stringify-without-jsonify"
import { Lang } from "@scandic-hotels/common/constants/language"
import { selectRate } from "@scandic-hotels/common/constants/routes/hotelReservation"
import { getCacheClient } from "@scandic-hotels/common/dataCache"
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
import { createCounter } from "@scandic-hotels/common/telemetry"
import { chunk } from "@scandic-hotels/common/utils/chunk"
@@ -64,6 +65,8 @@ import type {
import type { Cities } from "./output"
export const locationsAffix = "locations"
const hotelUtilsLogger = createLogger("hotelUtils")
export async function getCitiesByCountry({
countries,
lang,
@@ -101,8 +104,11 @@ export async function getCitiesByCountry({
const countryJson = await countryResponse.json()
const citiesByCountry = citiesByCountrySchema.safeParse(countryJson)
if (!citiesByCountry.success) {
console.error(`Unable to parse cities by country ${country}`)
console.error(citiesByCountry.error)
hotelUtilsLogger.error(
`Unable to parse cities by country ${country}`,
citiesByCountry.error
)
throw new Error(`Unable to parse cities by country ${country}`)
}
return { ...citiesByCountry.data, country }
@@ -160,8 +166,10 @@ export async function getCountries({
const countriesJson = await countryResponse.json()
const countries = countriesSchema.safeParse(countriesJson)
if (!countries.success) {
console.info(`Validation for countries failed`)
console.error(countries.error)
hotelUtilsLogger.error(
`Validation for countries failed`,
countries.error
)
return null
}
@@ -447,8 +455,10 @@ export async function getLocations({
const apiJson = await apiResponse.json()
const verifiedLocations = locationsSchema.safeParse(apiJson)
if (!verifiedLocations.success) {
console.info(`Locations Verification Failed`)
console.error(verifiedLocations.error)
hotelUtilsLogger.error(
`Locations Verification Failed`,
verifiedLocations.error
)
throw new Error("Unable to parse locations")
}
const chunkedLocations = chunk(verifiedLocations.data.data, 10)
@@ -471,10 +481,10 @@ export async function getLocations({
country,
}
} else {
console.info(
`Location cannot be found in any of the countries cities`
hotelUtilsLogger.error(
`Location cannot be found in any of the countries cities`,
location
)
console.info(location)
}
}
} else if (location.type === "hotels") {
@@ -614,9 +624,10 @@ export async function getCity({
const cityJson = await cityResponse.json()
const city = citiesSchema.safeParse(cityJson)
if (!city.success) {
console.info(`Validation of city failed`)
console.info(`cityUrl: ${cityUrl}`)
console.error(city.error)
hotelUtilsLogger.error(`Validation of city failed`, {
error: city.error,
cityUrl,
})
return null
}