Class: RosettAi::Telemetry::LogRotator

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/telemetry/log_rotator.rb

Overview

Rotates telemetry log files when they exceed a size threshold.

Rotated files are numbered .1 through .N, where .1 is the most recent. The oldest file is deleted when max_files is exceeded.

Author:

  • hugo

  • claude

Constant Summary collapse

DEFAULT_MAX_SIZE =

10 MB

10 * 1024 * 1024
DEFAULT_MAX_FILES =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, max_size: DEFAULT_MAX_SIZE, max_files: DEFAULT_MAX_FILES) ⇒ LogRotator

Returns a new instance of LogRotator.

Parameters:

  • path (String)

    log file path

  • max_size (Integer) (defaults to: DEFAULT_MAX_SIZE)

    rotation threshold in bytes (default: 10 MB)

  • max_files (Integer) (defaults to: DEFAULT_MAX_FILES)

    number of rotated files to keep (default: 5)



25
26
27
28
29
# File 'lib/rosett_ai/telemetry/log_rotator.rb', line 25

def initialize(path:, max_size: DEFAULT_MAX_SIZE, max_files: DEFAULT_MAX_FILES)
  @path = path
  @max_size = max_size
  @max_files = max_files
end

Instance Attribute Details

#pathString (readonly)

Returns path to the log file.

Returns:

  • (String)

    path to the log file



20
21
22
# File 'lib/rosett_ai/telemetry/log_rotator.rb', line 20

def path
  @path
end

Instance Method Details

#rotate_if_needed!Boolean

Rotate the log file if it exceeds the size threshold.

Returns:

  • (Boolean)

    true if rotation occurred



34
35
36
37
38
39
40
# File 'lib/rosett_ai/telemetry/log_rotator.rb', line 34

def rotate_if_needed! # rubocop:disable Naming/PredicateMethod -- mutates state, not a pure predicate
  return false unless File.exist?(@path)
  return false unless File.size(@path) >= @max_size

  rotate!
  true
end