Class: Tracing::FileAppender
- Inherits:
-
BaseAppender
- Object
- BaseAppender
- Tracing::FileAppender
- Extended by:
- DefaultPath
- Includes:
- DefaultPath
- Defined in:
- lib/appenders/file_appender.rb
Overview
File Appender
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BaseAppender
Attributes included from FilterUse
Attributes included from Tracing::Filter::ExecUse
Attributes included from Tracing::Filter::Registration
Instance Method Summary collapse
- #create_initial_file(file) ⇒ Object
- #file_path(file) ⇒ Object
- #insert_into_file(file, txt, marker_txt) ⇒ Object
-
#is_old_file?(file) ⇒ Boolean
helper for deciding file “write mode”.
-
#write_file(file, txt) ⇒ Object
file.
Methods included from DefaultPath
Methods inherited from BaseAppender
#allow_append, create_template, #handle, #initialize, #not_allow_append, register_templates, #time_limit
Methods included from Tracing::Filter::Registration
#_register_filters, #create_filters, #register_filters, #unregister_filters
Constructor Details
This class inherits a constructor from Tracing::BaseAppender
Instance Method Details
#create_initial_file(file) ⇒ Object
36 37 |
# File 'lib/appenders/file_appender.rb', line 36 def create_initial_file(file) end |
#file_path(file) ⇒ Object
58 59 60 61 |
# File 'lib/appenders/file_appender.rb', line 58 def file_path(file) def_path = default_path || self.class.default_path file = File.join(def_path, file) if self.class.default_path end |
#insert_into_file(file, txt, marker_txt) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/appenders/file_appender.rb', line 39 def insert_into_file(file, txt, marker_txt) line = marker_txt file = file_path(file) if !File.exist?(file) create_initial_file(file) end gsub_file file, /(#{Regexp.escape(line)})/mi do |match| "#{txt}\n#{match}" end end |
#is_old_file?(file) ⇒ Boolean
helper for deciding file “write mode”
54 55 56 |
# File 'lib/appenders/file_appender.rb', line 54 def is_old_file?(file) File.new(file).mtime < (Time.now - time_limit) end |
#write_file(file, txt) ⇒ Object
file
27 28 29 30 31 32 33 34 |
# File 'lib/appenders/file_appender.rb', line 27 def write_file(file, txt) file = file_path(file) write_mode = mode(file) File.open(file, write_mode) do |f| f.puts txt end end |