Skip to content

Commit

Permalink
perf: reuse the stream
Browse files Browse the repository at this point in the history
  • Loading branch information
cxtom committed Mar 31, 2021
1 parent 6a88434 commit 333a5fe
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/logger/src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ export default function (streamsArray) {

for (let dest of streams) {
if (dest.app === info.app && dest.level <= info.level) {
const fullpah = dest.fullpath;
const fullpath = dest.fullpath;
const [year, month, day, hour] = getTime(Date.now());
stream = pino.destination(`${fullpah}.${year}${month}${day}${hour}`);
const suffix = `${year}${month}${day}${hour}`;

if (dest.suffix === suffix) {
stream = dest.stream;
}
else {
stream = dest.stream = pino.destination(`${fullpath}.${year}${month}${day}${hour}`);
dest.suffix = suffix;
}

if (stream[metadata]) {
const {
lastTime,
Expand All @@ -44,7 +53,6 @@ export default function (streamsArray) {
stream.lastObj = lastObj;
stream.lastLogger = lastLogger;
}
dest.stream = stream;
}
if (stream) {
break;
Expand Down

0 comments on commit 333a5fe

Please sign in to comment.