Class: Tracing::FileAppender

Inherits:
BaseAppender show all
Extended by:
DefaultPath
Includes:
DefaultPath
Defined in:
lib/appenders/file_appender.rb

Overview

File Appender

Direct Known Subclasses

HtmlAppender, TemplateLogAppender, XmlAppender

Instance Attribute Summary

Attributes inherited from BaseAppender

#options, #templates

Attributes included from FilterUse

#filters

Attributes included from Tracing::Filter::ExecUse

#filter_executor

Attributes included from Tracing::Filter::Registration

#filters

Instance Method Summary collapse

Methods included from DefaultPath

default_path, default_path=

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”

Returns:

  • (Boolean)


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