From 1987215c08b4fe5791411a76312d92082ebcacea Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Fri, 1 Mar 2024 16:09:29 -0500 Subject: [PATCH] fix: Use fixed patch for pino-pretty colorized message --- .gitignore | 1 + package-lock.json | 4 ++-- patches/pino-pretty+10.3.1.patch | 33 ++++++++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 2e0a8ba..e88fee1 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ node_modules/ .tshy .tshy-build-tmp dist +tmp-* diff --git a/package-lock.json b/package-lock.json index 230fc20..40ef420 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@foxxmd/logging", - "version": "0.1.0", + "version": "0.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@foxxmd/logging", - "version": "0.1.0", + "version": "0.0.2", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/patches/pino-pretty+10.3.1.patch b/patches/pino-pretty+10.3.1.patch index f29ca79..e05a9b9 100644 --- a/patches/pino-pretty+10.3.1.patch +++ b/patches/pino-pretty+10.3.1.patch @@ -37,7 +37,7 @@ index 614d375..07dc628 100644 type PrettyStream = Transform & OnUnknown; type ColorizerFactory = typeof colorizerFactory; diff --git a/node_modules/pino-pretty/lib/colors.js b/node_modules/pino-pretty/lib/colors.js -index 5bb3804..0896ae7 100644 +index 5bb3804..f135c33 100644 --- a/node_modules/pino-pretty/lib/colors.js +++ b/node_modules/pino-pretty/lib/colors.js @@ -1,7 +1,5 @@ @@ -91,7 +91,15 @@ index 5bb3804..0896ae7 100644 return customColoredColorizer } -@@ -105,6 +96,7 @@ function customColoredColorizerFactory (customColors, useOnlyCustomProps) { +@@ -88,6 +79,7 @@ function customColoredColorizerFactory (customColors, useOnlyCustomProps) { + const customColoredColorizer = function (level, opts) { + return colorizeLevelCustom(level, customColored, opts) + } ++ customColoredColorizer.colors = availableColors + customColoredColorizer.message = customColoredColorizer.message || customColored.message + customColoredColorizer.greyMessage = customColoredColorizer.greyMessage || customColored.greyMessage + +@@ -105,6 +97,7 @@ function customColoredColorizerFactory (customColors, useOnlyCustomProps) { * recognized. * @property {function} message Accepts one string parameter that will be * colorized to a predefined color. @@ -264,10 +272,10 @@ index 7758f1d..ee2f3dc 100644 } if (messageKey in log === false) return undefined diff --git a/node_modules/pino-pretty/lib/utils/prettify-message.test.js b/node_modules/pino-pretty/lib/utils/prettify-message.test.js -index 8faf4b1..291f971 100644 +index 8faf4b1..dadf8b1 100644 --- a/node_modules/pino-pretty/lib/utils/prettify-message.test.js +++ b/node_modules/pino-pretty/lib/utils/prettify-message.test.js -@@ -185,3 +185,37 @@ tap.test('`messageFormat` supports function definition', async t => { +@@ -185,3 +185,54 @@ tap.test('`messageFormat` supports function definition', async t => { }) t.equal(str, '--> localhost/test') }) @@ -289,6 +297,23 @@ index 8faf4b1..291f971 100644 + t.equal(str, '\u001B[36m--> \u001B[31mlocalhost/test\u001B[36m\u001B[39m') +}) + ++tap.test('`messageFormat` supports function definition with colorizer object when using custom colors', async t => { ++ const colorizer = getColorizer(true, [[30, 'brightGreen']], false) ++ const str = prettifyMessage({ ++ log: { level: 30, request: { url: 'localhost/test' }, msg: 'incoming request' }, ++ context: { ++ ...context, ++ colorizer, ++ messageFormat: (log, messageKey, levelLabel, { colors }) => { ++ let msg = log[messageKey] ++ if (msg === 'incoming request') msg = `--> ${colors.red(log.request.url)}` ++ return msg ++ } ++ } ++ }) ++ t.equal(str, '\u001B[36m--> \u001B[31mlocalhost/test\u001B[36m\u001B[39m') ++}) ++ +tap.test('`messageFormat` supports function definition with colorizer object when no color is supported', async t => { + const colorizer = getColorizer(false) + const str = prettifyMessage({ -- 2.51.2