Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(lib): replace redundant reduce call on array #59

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion benchmark/format-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
const benchmark = require('benchmark')
const messageFormatFactory = require('../lib/messageFormatFactory')

const formatMessageColorized = messageFormatFactory(true)
const colors = {
60: 'red',
50: 'red',
40: 'yellow',
30: 'green',
20: 'blue',
10: 'cyan'
}
const formatMessageColorized = messageFormatFactory(true, colors, true)
const log = {
time: Date.now(),
level: 30,
Expand Down
10 changes: 4 additions & 6 deletions lib/messageFormatFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ const formatDate = require('./formatDate')
const colorizerFactory = require('pino-pretty').colorizerFactory

const messageFormatFactory = (levels, colors, useColors) => {
const customColors =
colors != null
? Object.entries(colors).reduce((colors, [level, color]) => {
return [...colors, [level, color]]
}, [])
: undefined
let customColors
if (colors != null) {
customColors = Object.entries(colors)
}
const colorizer = colorizerFactory(useColors, customColors)

const levelLookUp = {
Expand Down
Loading