Skip to content

Conversation

aniketdivekar
Copy link
Contributor

@aniketdivekar aniketdivekar commented Aug 13, 2025

User description

This is how the logs will look... For local testing, I created file per 100KB - actual code has 10MB size for rollover.

image

PR Type

Enhancement


Description

  • Switch log rotation to hourly with dateFile appender

  • Add 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 📝

Relevant files
Enhancement
logs.ts
Switch log rotation to hourly `dateFile` with new options

src/config/logs.ts

  • Changed log appenders for main, app, and p2p to use dateFile type
  • Set hourly rotation pattern (yyyy-MM-dd-hh) for these logs
  • Added new options: keepFileExt, numBackups (set to 24), compress,
    alwaysIncludePattern
  • Retained previous settings for other appenders
  • +30/-3   
    index.ts
    Support filename assignment for `dateFile` appenders         

    src/logger/index.ts

  • Modified logic to support both file and dateFile appenders when
    assigning filenames
  • +1/-1     
    shardus-types.ts
    Update log configuration types for new rotation options   

    src/shardus/shardus-types.ts

  • Extended type definitions for main, app, and p2p log appenders
  • Added new optional fields: pattern, keepFileExt, numBackups, compress,
    alwaysIncludePattern
  • +15/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🏅 Score: 92
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Configuration Consistency

    Ensure that the new log rotation options (such as pattern, numBackups, compress, etc.) are supported by the logger implementation and are compatible with the logging library in use. Misconfiguration could result in logs not rotating as expected or errors at runtime.

    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,
    },
    Appender Type Handling

    The logic now includes both 'file' and 'dateFile' types for filename assignment. Confirm that all custom and third-party appenders used in the configuration are handled correctly, and that no unintended appenders are affected by this change.

    if (appender.type !== 'file' && appender.type !== 'dateFile') continue
    appender.filename = `${this.logDir}/${key}.log`

    Comment on lines 11 to 40
    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,
    },

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    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]

    Suggested change
    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,
    },

    Comment on lines +204 to 206
    if (appender.type !== 'file' && appender.type !== 'dateFile') continue
    appender.filename = `${this.logDir}/${key}.log`
    }

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    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]

    Suggested change
    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`

    @justin-shardeum justin-shardeum changed the title feat: log file rotation strategy changes SHARD-2741 - feat: log file rotation strategy changes Sep 3, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant