Skip to content

Commit

Permalink
feat: use loglayer 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo Gravity committed Jan 2, 2025
1 parent 62297d3 commit 40a597a
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 268 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# fastify-starter-turbo-monorepo

## Jan-1-2025

- Package updates.
- Use version 5 of `loglayer`.

## Dec-7-2024

- Package updates.
Expand Down
23 changes: 12 additions & 11 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,43 @@
"verify-types": "tsc --project tsconfig.json --noEmit"
},
"dependencies": {
"@dotenvx/dotenvx": "1.28.0",
"@dotenvx/dotenvx": "1.32.0",
"@fastify/cors": "10.0.1",
"@fastify/jwt": "9.0.1",
"@fastify/jwt": "9.0.2",
"@fastify/swagger": "9.4.0",
"@fastify/swagger-ui": "5.2.0",
"@fastify/type-provider-typebox": "5.1.0",
"@internal/backend-errors": "workspace:*",
"@loglayer/transport-pino": "1.0.0",
"@sinclair/typebox": "0.33.22",
"ajv-formats": "3.0.1",
"asyncforge": "0.5.0",
"bcrypt": "5.1.1",
"chalk": "5.3.0",
"chalk": "5.4.1",
"dotenv": "16.4.7",
"env-var": "7.5.0",
"fastify": "5.1.0",
"fastify-cli": "7.0.1",
"fastify": "5.2.0",
"fastify-cli": "7.3.0",
"fastify-plugin": "5.0.1",
"kysely": "0.27.4",
"loglayer": "4.8.0",
"kysely": "0.27.5",
"loglayer": "5.0.0",
"nanoid": "5.0.9",
"pg": "8.13.1",
"pino": "9.5.0",
"pino": "9.6.0",
"pino-pretty": "13.0.0",
"serialize-error": "11.0.3",
"tsc-module-loader": "0.0.1",
"uuid": "11.0.3",
"yaml": "2.6.1"
"yaml": "2.7.0"
},
"devDependencies": {
"@faker-js/faker": "9.3.0",
"@internal/tsconfig": "workspace:*",
"@testcontainers/postgresql": "10.16.0",
"@turbo/gen": "2.3.3",
"@types/node": "22.10.1",
"@types/node": "22.10.3",
"@types/pg": "8.11.10",
"kysely-ctl": "0.9.0",
"kysely-ctl": "0.10.1",
"ts-node": "10.9.2",
"tsx": "4.19.2",
"typescript": "5.7.2",
Expand Down
3 changes: 1 addition & 2 deletions apps/backend/src/plugins/context.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { FastifyInstance } from "fastify";
import fp from "fastify-plugin";
import type { LogLayer } from "loglayer";
import type { P } from "pino";
import { ApiContext } from "../api-lib/context";
import { db } from "../db";
import { removeQueryParametersFromPath } from "../utils/remove-query-params";
Expand All @@ -24,7 +23,7 @@ async function plugin(fastify: FastifyInstance, _opts) {

request.ctx = new ApiContext({
db,
log: request.log as unknown as LogLayer<P.Logger>,
log: request.log as unknown as LogLayer,
});
});
}
Expand Down
3 changes: 1 addition & 2 deletions apps/backend/src/utils/async-local-storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AsyncLocalStorage } from "node:async_hooks";
import type { ILogLayer } from "loglayer";
import type { P } from "pino";

export const asyncLocalStorage = new AsyncLocalStorage<{ logger: ILogLayer<P.Logger> }>();
export const asyncLocalStorage = new AsyncLocalStorage<{ logger: ILogLayer }>();
32 changes: 13 additions & 19 deletions apps/backend/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { PinoTransport } from "@loglayer/transport-pino";
import chalk from "chalk";
import { type ILogLayer, LogLayer, LoggerType } from "loglayer";
import { type ILogLayer, LogLayer } from "loglayer";
import { type LogDescriptor, type P, pino } from "pino";
import { prettyFactory } from "pino-pretty";
import { serializeError } from "serialize-error";
import { BACKEND_LOG_LEVEL, IS_PROD, IS_TEST } from "../constants";
import { asyncLocalStorage } from "./async-local-storage";

declare module "fastify" {
interface FastifyBaseLogger extends LogLayer<P.Logger> {}
interface FastifyBaseLogger extends LogLayer {}
}

let p: P.Logger;
Expand Down Expand Up @@ -102,22 +103,15 @@ if (IS_TEST) {
);
}

const logger = new LogLayer<P.Logger>({
logger: {
instance: p,
type: LoggerType.PINO,
},
context: {
fieldName: "context",
},
metadata: {
fieldName: "metadata",
},
error: {
fieldName: "err",
serializer: serializeError,
copyMsgOnOnlyError: true,
},
const logger = new LogLayer({
transport: new PinoTransport({
logger: p,
}),
contextFieldName: "context",
metadataFieldName: "metadata",
errorFieldName: "err",
errorSerializer: serializeError,
copyMsgOnOnlyError: true,
plugins: [
{
onBeforeMessageOut: ({ messages }) => {
Expand All @@ -140,7 +134,7 @@ if (IS_TEST) {
logger.disableLogging();
}

export function getLogger(): ILogLayer<P.Logger> {
export function getLogger(): ILogLayer {
if (IS_TEST) {
return logger;
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.10",
"@commitlint/cli": "19.6.0",
"@changesets/cli": "2.27.11",
"@commitlint/cli": "19.6.1",
"@commitlint/config-conventional": "19.6.0",
"@internal/tsconfig": "workspace:*",
"@types/node": "22.10.1",
"@types/node": "22.10.3",
"husky": "9.1.7",
"syncpack": "13.0.0",
"turbo": "2.3.3",
Expand Down
Loading

0 comments on commit 40a597a

Please sign in to comment.