From 705d9bfc31b78e2aaf49829c42e0ab3c7726451d Mon Sep 17 00:00:00 2001 From: Matteo Vivona Date: Wed, 27 Nov 2024 18:37:31 +0100 Subject: [PATCH 1/5] fix: logger options only accepts a configuration object #479 --- package.json | 4 ++-- src/app.ts | 4 ++-- src/logger.ts | 43 ++++++++++++++++++------------------------- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index b92293ed..e9d1cb76 100644 --- a/package.json +++ b/package.json @@ -94,9 +94,9 @@ }, "homepage": "https://github.com/ducktors/turborepo-remote-cache#readme", "engines": { - "node": ">=20.0.0", - "pnpm": ">=9.0.0" + "node": ">=20.0.0" }, + "packageManager": "pnpm@9.14.2", "keywords": [ "turborepo", "monorepo", diff --git a/src/app.ts b/src/app.ts index 833c5ad7..a6475bb7 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,7 +1,7 @@ import { isBoom } from '@hapi/boom' import Fastify, { FastifyInstance, FastifyServerOptions } from 'fastify' import hyperid from 'hyperid' -import { logger } from './logger.js' +import { loggerConfig } from './logger.js' import config from './plugins/config.js' import remoteCache from './plugins/remote-cache/index.js' @@ -9,7 +9,7 @@ const uuid = hyperid({ urlSafe: true }) export function createApp(options: FastifyServerOptions = {}): FastifyInstance { const app = Fastify({ - logger, + logger: loggerConfig, genReqId: () => uuid(), ...options, }) diff --git a/src/logger.ts b/src/logger.ts index 484fc690..b4671a97 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -10,34 +10,27 @@ const PinoLevelToSeverityLookup = { fatal: 'CRITICAL', } as const -let logDestination - const env = _env.get() -if (env.LOG_MODE === 'file') { - logDestination = pino.destination(env.LOG_FILE) -} else if (env.LOG_MODE === 'stdout') { - logDestination = process.stdout -} else { - throw new Error('Invalid LOG_MODE. Allowed values are "file" or "stdout".') -} - -export const logger = pino( - { - level: env.LOG_LEVEL, - messageKey: 'message', - redact: ['req.headers.authorization'], - formatters: { - level(label, number) { - return { - severity: - PinoLevelToSeverityLookup[label] || PinoLevelToSeverityLookup.info, - level: number, - } - }, +export const loggerConfig = { + level: env.LOG_LEVEL, + messageKey: 'message', + redact: ['req.headers.authorization'], + formatters: { + level(label, number) { + return { + severity: + PinoLevelToSeverityLookup[label] || PinoLevelToSeverityLookup.info, + level: number, + } }, }, - logDestination, -) + transport: + env.LOG_MODE === 'file' + ? { target: 'pino/file', options: { destination: env.LOG_FILE } } + : undefined, +} + +export const logger = pino(loggerConfig) export default logger From 9f5f9246b099c1986c38400175ed27e2be9cb076 Mon Sep 17 00:00:00 2001 From: Matteo Vivona Date: Wed, 27 Nov 2024 18:41:12 +0100 Subject: [PATCH 2/5] ci: update pnpm on pipeline --- .github/workflows/ci.yml | 4 ++-- .github/workflows/release.yml | 2 +- .github/workflows/test.yaml | 2 +- package.json | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c0b2cc3..7688711a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: - uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 name: Install pnpm with: - version: 9 + version: 9.14.2 - name: Install with pnpm run: pnpm install --frozen-lockfile - name: Check commit message @@ -97,7 +97,7 @@ jobs: - uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 name: Install pnpm with: - version: 9 + version: 9.14.2 - name: Install with pnpm run: pnpm install - name: Lint code diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 211e0afb..2207f2ad 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,7 +39,7 @@ jobs: - uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 name: Install pnpm with: - version: 9 + version: 9.14.2 - name: Install dependencies run: pnpm install - name: Verify the integrity of provenance attestations and registry signatures for installed dependencies diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 44c472db..05968abc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -31,7 +31,7 @@ jobs: - uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 name: Install pnpm with: - version: 9 + version: 9.14.2 - name: Install with pnpm run: pnpm install - name: Run tests with coverage diff --git a/package.json b/package.json index e9d1cb76..15614abb 100644 --- a/package.json +++ b/package.json @@ -94,9 +94,9 @@ }, "homepage": "https://github.com/ducktors/turborepo-remote-cache#readme", "engines": { - "node": ">=20.0.0" + "node": ">=20.13.1", + "pnpm": ">=9.14.2" }, - "packageManager": "pnpm@9.14.2", "keywords": [ "turborepo", "monorepo", From 5c7d495d1e811f9fe4456b10e0f039d3e76bd9eb Mon Sep 17 00:00:00 2001 From: Matteo Vivona Date: Wed, 27 Nov 2024 18:56:51 +0100 Subject: [PATCH 3/5] fix: change logger config --- README.md | 2 +- package.json | 4 ++-- src/app.ts | 4 ++-- src/logger.ts | 6 ++---- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 699aae93..c616f6cc 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ![remote_cache_1](https://user-images.githubusercontent.com/1620916/216358421-36a63b0e-d1f6-484f-a4ca-6a7119cc0816.jpg) -[![GitHub package.json version](https://img.shields.io/github/package-json/v/ducktors/turborepo-remote-cache)](https://github.com/ducktors/turborepo-remote-cache/releases) [![CI](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/ci.yml) [![Test](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/test.yaml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/test.yaml) [![Release](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/release.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/release.yml) [![Docker](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/docker.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/docker.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/bbb26ca5247dee70dde0/maintainability)](https://codeclimate.com/github/ducktors/turborepo-remote-cache/maintainability) [![Coverage Status](https://coveralls.io/repos/github/ducktors/turborepo-remote-cache/badge.svg?branch=main)](https://coveralls.io/github/ducktors/turborepo-remote-cache?branch=main) [![Docker Pulls](https://img.shields.io/docker/pulls/ducktors/turborepo-remote-cache?logo=docker)](https://hub.docker.com/r/ducktors/turborepo-remote-cache) [![npm](https://img.shields.io/npm/dt/turborepo-remote-cache)](https://www.npmjs.com/package/turborepo-remote-cache) [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/ducktors/turborepo-remote-cache/badge)](https://securityscorecards.dev/viewer/?uri=github.com/ducktors/turborepo-remote-cache) +[![GitHub package.json version](https://img.shields.io/github/package-json/v/ducktors/turborepo-remote-cache)](https://github.com/ducktors/turborepo-remote-cache/releases) ![node:20.13.1](https://img.shields.io/badge/node-20.13.1-lightgreen) ![pnpm@9.14.2](https://img.shields.io/badge/pnpm-9.14.2-yellow) [![CI](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/ci.yml) [![Test](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/test.yaml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/test.yaml) [![Release](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/release.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/release.yml) [![Docker](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/docker.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/docker.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/bbb26ca5247dee70dde0/maintainability)](https://codeclimate.com/github/ducktors/turborepo-remote-cache/maintainability) [![Coverage Status](https://coveralls.io/repos/github/ducktors/turborepo-remote-cache/badge.svg?branch=main)](https://coveralls.io/github/ducktors/turborepo-remote-cache?branch=main) [![Docker Pulls](https://img.shields.io/docker/pulls/ducktors/turborepo-remote-cache?logo=docker)](https://hub.docker.com/r/ducktors/turborepo-remote-cache) [![npm](https://img.shields.io/npm/dt/turborepo-remote-cache)](https://www.npmjs.com/package/turborepo-remote-cache) [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/ducktors/turborepo-remote-cache/badge)](https://securityscorecards.dev/viewer/?uri=github.com/ducktors/turborepo-remote-cache) [![All Contributors](https://img.shields.io/badge/all_contributors-30-orange.svg?style=flat-square)](#contributors-) diff --git a/package.json b/package.json index 15614abb..5e37a6b3 100644 --- a/package.json +++ b/package.json @@ -58,8 +58,8 @@ "fastify-plugin": "5.0.1", "fs-blob-store": "6.0.0", "hyperid": "3.1.1", - "pino": "9.5.0", - "pino-pretty": "13.0.0", + "pino": "^9.5.0", + "pino-pretty": "^13.0.0", "s3-blob-store": "4.1.1" }, "devDependencies": { diff --git a/src/app.ts b/src/app.ts index a6475bb7..f8fdf950 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,7 +1,7 @@ import { isBoom } from '@hapi/boom' import Fastify, { FastifyInstance, FastifyServerOptions } from 'fastify' import hyperid from 'hyperid' -import { loggerConfig } from './logger.js' +import { logger } from './logger.js' import config from './plugins/config.js' import remoteCache from './plugins/remote-cache/index.js' @@ -9,7 +9,7 @@ const uuid = hyperid({ urlSafe: true }) export function createApp(options: FastifyServerOptions = {}): FastifyInstance { const app = Fastify({ - logger: loggerConfig, + loggerInstance: logger, genReqId: () => uuid(), ...options, }) diff --git a/src/logger.ts b/src/logger.ts index b4671a97..3a7818be 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -12,7 +12,7 @@ const PinoLevelToSeverityLookup = { const env = _env.get() -export const loggerConfig = { +export const logger = pino({ level: env.LOG_LEVEL, messageKey: 'message', redact: ['req.headers.authorization'], @@ -29,8 +29,6 @@ export const loggerConfig = { env.LOG_MODE === 'file' ? { target: 'pino/file', options: { destination: env.LOG_FILE } } : undefined, -} - -export const logger = pino(loggerConfig) +}) export default logger From 5de897fe99283ad0ae6f57f80529935386554981 Mon Sep 17 00:00:00 2001 From: Matteo Vivona Date: Wed, 27 Nov 2024 19:02:12 +0100 Subject: [PATCH 4/5] chore: update pnpm-lock --- pnpm-lock.yaml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 68d17cb2..46a7d405 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -48,10 +48,10 @@ importers: specifier: 3.1.1 version: 3.1.1 pino: - specifier: 9.5.0 + specifier: ^9.5.0 version: 9.5.0 pino-pretty: - specifier: 13.0.0 + specifier: ^13.0.0 version: 13.0.0 s3-blob-store: specifier: 4.1.1 @@ -3017,10 +3017,6 @@ packages: safe-regex2@4.0.0: resolution: {integrity: sha512-Hvjfv25jPDVr3U+4LDzBuZPPOymELG3PYcSk5hcevooo1yxxamQL/bHs/GrEPGmMoMEwRrHVGiCA1pXi97B8Ew==} - safe-stable-stringify@2.4.2: - resolution: {integrity: sha512-gMxvPJYhP0O9n2pvcfYfIuYgbledAOJFcqRThtPRmjscaipiwcwPPKLytpVzMkG2HAN87Qmo2d4PtGiri1dSLA==} - engines: {node: '>=10'} - safe-stable-stringify@2.4.3: resolution: {integrity: sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==} engines: {node: '>=10'} @@ -6033,7 +6029,7 @@ snapshots: '@colors/colors': 1.5.0 fecha: 4.2.3 ms: 2.1.3 - safe-stable-stringify: 2.4.2 + safe-stable-stringify: 2.4.3 triple-beam: 1.3.0 longest@2.0.1: {} @@ -6622,8 +6618,6 @@ snapshots: dependencies: ret: 0.5.0 - safe-stable-stringify@2.4.2: {} - safe-stable-stringify@2.4.3: {} safer-buffer@2.1.2: {} @@ -7108,7 +7102,7 @@ snapshots: logform: 2.4.2 one-time: 1.0.0 readable-stream: 3.6.2 - safe-stable-stringify: 2.4.2 + safe-stable-stringify: 2.4.3 stack-trace: 0.0.10 triple-beam: 1.3.0 winston-transport: 4.5.0 From 3a486ff940a0c6489d76ec958ece8d0ee46d82de Mon Sep 17 00:00:00 2001 From: Matteo Vivona Date: Wed, 27 Nov 2024 19:06:17 +0100 Subject: [PATCH 5/5] chore: update node engine --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5e37a6b3..82b6896e 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,7 @@ }, "homepage": "https://github.com/ducktors/turborepo-remote-cache#readme", "engines": { - "node": ">=20.13.1", + "node": ">=20.0.0", "pnpm": ">=9.14.2" }, "keywords": [