Class: Makit::Logging::Sinks::FileSink
- Defined in:
- lib/makit/logging/sinks/file_sink.rb
Overview
File sink for writing log entries to files
This sink is a thin wrapper around UnifiedFileSink that provides a simpler API for single-file logging. It maintains backward compatibility with the original FileSink interface while leveraging the more robust UnifiedFileSink implementation.
Instance Attribute Summary collapse
-
#append ⇒ Boolean
readonly
Whether to append to existing file (true) or overwrite (false).
-
#formatter ⇒ Symbol
readonly
The formatter format name.
-
#log_file ⇒ String
readonly
Path to the log file.
-
#unified_sink ⇒ UnifiedFileSink
readonly
The underlying unified sink.
Instance Method Summary collapse
-
#call(log_request) {|LogRequest| ... } ⇒ LogRequest
Execute sink logic to write log entry to file.
-
#config ⇒ Hash
Get sink configuration.
-
#initialize(log_file: "makit.log", formatter: :json, append: true, **formatter_options) ⇒ FileSink
constructor
Initialize file sink.
Methods inherited from Base
Constructor Details
#initialize(log_file: "makit.log", formatter: :json, append: true, **formatter_options) ⇒ FileSink
Initialize file sink
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/makit/logging/sinks/file_sink.rb', line 52 def initialize(log_file: "makit.log", formatter: :json, append: true, **) @log_file = log_file @formatter = formatter.to_sym @append = append # Create unified sink configuration config = { file: @log_file, format: @formatter, append: @append, }.merge() @unified_sink = UnifiedFileSink.new(configurations: [config]) end |
Instance Attribute Details
#append ⇒ Boolean (readonly)
Returns whether to append to existing file (true) or overwrite (false).
39 40 41 |
# File 'lib/makit/logging/sinks/file_sink.rb', line 39 def append @append end |
#formatter ⇒ Symbol (readonly)
Returns the formatter format name.
37 38 39 |
# File 'lib/makit/logging/sinks/file_sink.rb', line 37 def formatter @formatter end |
#log_file ⇒ String (readonly)
Returns path to the log file.
35 36 37 |
# File 'lib/makit/logging/sinks/file_sink.rb', line 35 def log_file @log_file end |
#unified_sink ⇒ UnifiedFileSink (readonly)
Returns the underlying unified sink.
41 42 43 |
# File 'lib/makit/logging/sinks/file_sink.rb', line 41 def unified_sink @unified_sink end |
Instance Method Details
#call(log_request) {|LogRequest| ... } ⇒ LogRequest
Execute sink logic to write log entry to file
73 74 75 |
# File 'lib/makit/logging/sinks/file_sink.rb', line 73 def call(log_request, &block) @unified_sink.call(log_request, &block) end |
#config ⇒ Hash
Get sink configuration
80 81 82 83 84 85 86 87 88 |
# File 'lib/makit/logging/sinks/file_sink.rb', line 80 def config { name: self.class.name.split("::").last, log_file: @log_file, formatter: @formatter, append: @append, unified_config: @unified_sink.config, } end |