Skip to content

Commit

Permalink
(feat: TT-214) Use log rotation (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
keplervital authored May 3, 2023
1 parent c8d3342 commit 18385c2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"node-cache": "^5.1.2",
"node-forge": "^1.3.1",
"pako": "^2.1.0",
"pino": "^8.11.0"
"pino": "^8.11.0",
"rotating-file-stream": "^3.1.0"
}
}
13 changes: 9 additions & 4 deletions packages/core/src/commons/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pino from 'pino';
import { tmpdir } from 'os';
import { resolve } from 'path';
import { createStream } from 'rotating-file-stream';

const defaultLogFileName = `main`;
let logger: pino.Logger<pino.LoggerOptions>;
Expand All @@ -10,8 +10,6 @@ export const initLogger = (
logName: string = defaultLogFileName,
logFolder = tmpdir()
): void => {
const logPath = resolve(logFolder, `ic-http-proxy-${logName}.log`);

logger = pino(
{
name,
Expand All @@ -21,7 +19,14 @@ export const initLogger = (
},
},
pino.multistream([
pino.destination({ sync: false, dest: logPath }),
{
stream: createStream(`ic-http-proxy-${logName}.log`, {
size: '10M',
compress: 'gzip',
maxFiles: 5,
path: logFolder,
}),
},
{ stream: process.stdout },
])
);
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ __metadata:
pako: ^2.1.0
pino: ^8.11.0
prettier: ^2.8.4
rotating-file-stream: ^3.1.0
tsc-alias: ^1.8.5
typescript: ^4.9.5
languageName: unknown
Expand Down Expand Up @@ -4143,6 +4144,13 @@ __metadata:
languageName: node
linkType: hard

"rotating-file-stream@npm:^3.1.0":
version: 3.1.0
resolution: "rotating-file-stream@npm:3.1.0"
checksum: 2f5840ae7fee1c93403e042c87f3e90c329244f73d561afb4b3290e3d580c05d971fe72c70177c38fba734172a098b460bfe91b46f77236a2ff4b7b7ed35db18
languageName: node
linkType: hard

"run-parallel@npm:^1.1.9":
version: 1.2.0
resolution: "run-parallel@npm:1.2.0"
Expand Down

0 comments on commit 18385c2

Please sign in to comment.