Skip to content

Commit

Permalink
fix: Use fixed patch for pino-pretty colorized message
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Mar 1, 2024
1 parent aa8d87f commit 1987215
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ node_modules/
.tshy
.tshy-build-tmp
dist
tmp-*
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 29 additions & 4 deletions patches/pino-pretty+10.3.1.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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')
})
Expand All @@ -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({
Expand Down

0 comments on commit 1987215

Please sign in to comment.