Class: Tracing::XmlAppender
- Inherits:
-
FileAppender
- Object
- BaseAppender
- FileAppender
- Tracing::XmlAppender
- Defined in:
- lib/appenders/types/xml_appender.rb
Instance Attribute Summary collapse
-
#to_file ⇒ Object
Returns the value of attribute to_file.
-
#xml_output ⇒ Object
Returns the value of attribute xml_output.
Attributes inherited from BaseAppender
Attributes included from FilterUse
Attributes included from Filter::ExecUse
Attributes included from Filter::Registration
Class Method Summary collapse
Instance Method Summary collapse
-
#allow_append(txt, context) ⇒ Object
perform append.
- #create_initial_file(file) ⇒ Object
-
#initialize(init_options = nil) ⇒ XmlAppender
constructor
A new instance of XmlAppender.
-
#not_allow_append(lines, context) ⇒ Object
silently ignore.
- #write_wrap_file(file) ⇒ Object
- #xml_begin ⇒ Object
- #xml_end ⇒ Object
Methods inherited from FileAppender
#file_path, #insert_into_file, #is_old_file?, #write_file
Methods included from DefaultPath
Methods inherited from BaseAppender
create_template, #handle, register_templates, #time_limit
Methods included from Filter::Registration
#_register_filters, #create_filters, #register_filters, #unregister_filters
Constructor Details
#initialize(init_options = nil) ⇒ XmlAppender
Returns a new instance of XmlAppender.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/appenders/types/xml_appender.rb', line 20 def initialize( = nil) @tracer = Tracing::XmlTemplate.new super() @xml_output = xml_begin return if ! # write to file @to_file = [:to_file] if @to_file write_wrap_file(to_file) else xml_output << xml_begin << xml_end end end |
Instance Attribute Details
#to_file ⇒ Object
Returns the value of attribute to_file.
4 5 6 |
# File 'lib/appenders/types/xml_appender.rb', line 4 def to_file @to_file end |
#xml_output ⇒ Object
Returns the value of attribute xml_output.
4 5 6 |
# File 'lib/appenders/types/xml_appender.rb', line 4 def xml_output @xml_output end |
Class Method Details
.default_path ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/appenders/types/xml_appender.rb', line 7 def default_path return if !@default_path if !File.exists?(@default_path) FileUtils.mkdir_p @default_path end @default_path end |
.default_path=(path) ⇒ Object
15 16 17 |
# File 'lib/appenders/types/xml_appender.rb', line 15 def default_path=(path) @default_path = path end |
Instance Method Details
#allow_append(txt, context) ⇒ Object
perform append
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/appenders/types/xml_appender.rb', line 55 def allow_append(txt, context) # check if BEGIN or END if txt.include?('BEGIN') txt = tracer.handle_before_call(context) elsif txt.include?('END') txt = tracer.handle_after_call(context) end if to_file insert_into_file(to_file, txt, xml_end) else # insert into string xml_output = xml_output[0..-xml_end.length] + txt + xml_end end end |
#create_initial_file(file) ⇒ Object
35 36 37 |
# File 'lib/appenders/types/xml_appender.rb', line 35 def create_initial_file(file) write_wrap_file(file) end |
#not_allow_append(lines, context) ⇒ Object
silently ignore
72 73 |
# File 'lib/appenders/types/xml_appender.rb', line 72 def not_allow_append(lines, context) end |
#write_wrap_file(file) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/appenders/types/xml_appender.rb', line 39 def write_wrap_file(file) File.open(file, "w") do |file| file.puts xml_begin file.puts xml_end end end |
#xml_begin ⇒ Object
46 47 48 |
# File 'lib/appenders/types/xml_appender.rb', line 46 def xml_begin "<?xml version='1.0' encoding='UTF-8'?>\n<tracing>\n" end |
#xml_end ⇒ Object
50 51 52 |
# File 'lib/appenders/types/xml_appender.rb', line 50 def xml_end "</tracing>" end |