Skip to content

Commit

Permalink
perf(Fast time): Add a fastTime option
Browse files Browse the repository at this point in the history
Similar to `bole`: the `time` property can be a timestamp or a string.

Before

logga x 402,553 ops/sec ±0.17% (592 runs sampled)

After

logga x 469,130 ops/sec ±0.11% (593 runs sampled)
  • Loading branch information
nokome committed Jan 11, 2021
1 parent 5d4db3b commit 7259dba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ log4js.configure({

const loggaLogger = logga.getLogger('bench')
logga.replaceHandlers((entry) => {
logga.defaultHandler(entry, { exitOnError: false })
logga.defaultHandler(entry, { fastTime: true, exitOnError: false })
})

const loglevelLogger = loglevel.getLogger('bench')
Expand Down
7 changes: 6 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export function defaultHandler(
data: LogData,
options: {
maxLevel?: LogLevel
fastTime?: boolean
showStack?: boolean
exitOnError?: boolean
throttle?: {
Expand Down Expand Up @@ -284,7 +285,11 @@ export function defaultHandler(
process.stderr !== undefined &&
process.stderr.isTTY !== true
) {
entry = JSON.stringify({ time: new Date().toISOString(), ...data })
const { fastTime = false } = options
entry = JSON.stringify({
time: fastTime ? Date.now() : new Date().toISOString(),
...data,
})
} else {
const index = level < 0 ? 0 : level > 3 ? 3 : level
const label = LogLevel[index].toUpperCase().padEnd(5, ' ')
Expand Down

0 comments on commit 7259dba

Please # to comment.