Class: RosettAi::Telemetry::LogRotator
- Inherits:
-
Object
- Object
- RosettAi::Telemetry::LogRotator
- 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.
Constant Summary collapse
- DEFAULT_MAX_SIZE =
10 MB
10 * 1024 * 1024
- DEFAULT_MAX_FILES =
5
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
Path to the log file.
Instance Method Summary collapse
-
#initialize(path:, max_size: DEFAULT_MAX_SIZE, max_files: DEFAULT_MAX_FILES) ⇒ LogRotator
constructor
A new instance of LogRotator.
-
#rotate_if_needed! ⇒ Boolean
Rotate the log file if it exceeds the size threshold.
Constructor Details
#initialize(path:, max_size: DEFAULT_MAX_SIZE, max_files: DEFAULT_MAX_FILES) ⇒ LogRotator
Returns a new instance of LogRotator.
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
#path ⇒ String (readonly)
Returns 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.
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 |