SHARD-2741 - feat: log file rotation strategy changes#549
SHARD-2741 - feat: log file rotation strategy changes#549aniketdivekar wants to merge 5 commits intodevfrom
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
| main: { | ||
| type: 'dateFile', | ||
| pattern: 'yyyy-MM-dd-hh', | ||
| keepFileExt: true, | ||
| maxLogSize: 10000000, | ||
| backups: 10, | ||
| numBackups: 24, | ||
| compress: false, | ||
| alwaysIncludePattern: false, | ||
| }, | ||
| app: { | ||
| type: 'dateFile', | ||
| pattern: 'yyyy-MM-dd-hh', | ||
| keepFileExt: true, | ||
| maxLogSize: 10000000, | ||
| backups: 10, | ||
| numBackups: 24, | ||
| compress: false, | ||
| alwaysIncludePattern: false, | ||
| }, | ||
| p2p: { | ||
| type: 'dateFile', | ||
| pattern: 'yyyy-MM-dd-hh', | ||
| keepFileExt: true, | ||
| maxLogSize: 10000000, | ||
| backups: 10, | ||
| numBackups: 24, | ||
| compress: false, | ||
| alwaysIncludePattern: false, | ||
| }, |
There was a problem hiding this comment.
Suggestion: The pattern value 'yyyy-MM-dd-hh' may cause log files to rotate every hour, potentially leading to excessive file creation and disk usage. Consider using 'yyyy-MM-dd' for daily rotation unless hourly rotation is strictly required. [general, importance: 7]
| main: { | |
| type: 'dateFile', | |
| pattern: 'yyyy-MM-dd-hh', | |
| keepFileExt: true, | |
| maxLogSize: 10000000, | |
| backups: 10, | |
| numBackups: 24, | |
| compress: false, | |
| alwaysIncludePattern: false, | |
| }, | |
| app: { | |
| type: 'dateFile', | |
| pattern: 'yyyy-MM-dd-hh', | |
| keepFileExt: true, | |
| maxLogSize: 10000000, | |
| backups: 10, | |
| numBackups: 24, | |
| compress: false, | |
| alwaysIncludePattern: false, | |
| }, | |
| p2p: { | |
| type: 'dateFile', | |
| pattern: 'yyyy-MM-dd-hh', | |
| keepFileExt: true, | |
| maxLogSize: 10000000, | |
| backups: 10, | |
| numBackups: 24, | |
| compress: false, | |
| alwaysIncludePattern: false, | |
| }, | |
| main: { | |
| type: 'dateFile', | |
| pattern: 'yyyy-MM-dd', | |
| keepFileExt: true, | |
| maxLogSize: 10000000, | |
| backups: 10, | |
| numBackups: 24, | |
| compress: false, | |
| alwaysIncludePattern: false, | |
| }, | |
| app: { | |
| type: 'dateFile', | |
| pattern: 'yyyy-MM-dd', | |
| keepFileExt: true, | |
| maxLogSize: 10000000, | |
| backups: 10, | |
| numBackups: 24, | |
| compress: false, | |
| alwaysIncludePattern: false, | |
| }, | |
| p2p: { | |
| type: 'dateFile', | |
| pattern: 'yyyy-MM-dd', | |
| keepFileExt: true, | |
| maxLogSize: 10000000, | |
| backups: 10, | |
| numBackups: 24, | |
| compress: false, | |
| alwaysIncludePattern: false, | |
| }, |
| if (appender.type !== 'file' && appender.type !== 'dateFile') continue | ||
| appender.filename = `${this.logDir}/${key}.log` | ||
| } |
There was a problem hiding this comment.
Suggestion: Setting a filename property on appenders of type 'dateFile' may require the filename to include the pattern placeholder for correct log rotation. Ensure the filename supports pattern substitution if required by the logging library. [general, importance: 6]
| if (appender.type !== 'file' && appender.type !== 'dateFile') continue | |
| appender.filename = `${this.logDir}/${key}.log` | |
| } | |
| if (appender.type !== 'file' && appender.type !== 'dateFile') continue | |
| appender.filename = appender.type === 'dateFile' | |
| ? `${this.logDir}/${key}.log` | |
| : `${this.logDir}/${key}.log` | |
| // If the logging library requires, consider: `${this.logDir}/${key}.log` or `${this.logDir}/${key}-%DATE%.log` |
User description
This is how the logs will look... For local testing, I created file per 100KB - actual code has 10MB size for rollover.
PR Type
Enhancement
Description
Switch log rotation to hourly with
dateFileappenderAdd new log rotation options: pattern, numBackups, etc.
Update type definitions for new log config options
Ensure logger supports both 'file' and 'dateFile' appenders
Changes walkthrough 📝
logs.ts
Switch log rotation to hourly `dateFile` with new optionssrc/config/logs.ts
main,app, andp2pto usedateFiletypeyyyy-MM-dd-hh) for these logskeepFileExt,numBackups(set to 24),compress,alwaysIncludePatternindex.ts
Support filename assignment for `dateFile` appenderssrc/logger/index.ts
fileanddateFileappenders whenassigning filenames
shardus-types.ts
Update log configuration types for new rotation optionssrc/shardus/shardus-types.ts
main,app, andp2plog appenderspattern,keepFileExt,numBackups,compress,alwaysIncludePattern