Class: Tracing::BaseAppender

Inherits:
Object
  • Object
show all
Includes:
FilterUse
Defined in:
lib/appenders/base_appender.rb

Overview

base appender (abstract)

Direct Known Subclasses

FileAppender, LoggerAppender, StreamAppender

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes included from FilterUse

#filters

Attributes included from Filter::ExecUse

#filter_executor

Attributes included from Filter::Registration

#filters

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Filter::Registration

#_register_filters, #create_filters, #register_filters, #unregister_filters

Constructor Details

#initialize(init_options = nil) ⇒ BaseAppender

Returns a new instance of BaseAppender.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/appenders/base_appender.rb', line 31

def initialize(init_options = nil)          
  return if !init_options
  if init_options.kind_of? Hash
    @options = init_options[:options] || init_options
    register_filters(init_options[:filters])
    template = @options[:template] if @options
    return if !template

    @template = self.class.create_template(template)      
  elsif init_options.kind_of? Symbol
    self.class.register_templates
    tracer = self.class.templates[init_options]
    return if !tracer

    @template = self.class.create_template(template)
  else
    raise Exception, "Appender must be initialized with Hash"
  end
end

Class Attribute Details

.templatesObject

Returns the value of attribute templates.



10
11
12
# File 'lib/appenders/base_appender.rb', line 10

def templates
  @templates
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/appenders/base_appender.rb', line 6

def options
  @options
end

#templatesObject (readonly)

Returns the value of attribute templates.



7
8
9
# File 'lib/appenders/base_appender.rb', line 7

def templates
  @templates
end

Class Method Details

.create_template(template) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/appenders/base_appender.rb', line 18

def create_template(template)
  templates ||= register_templates
  if template.kind_of?(Symbol) || template.kind_of?(String)
    template_class = templates[template.to_sym] || templates[:default]
    template_class.new
  elsif template.kind_of? Tracing::BaseTemplate
    template
  else
    nil
  end
end

.register_templates(templates = nil) ⇒ Object



13
14
15
16
# File 'lib/appenders/base_appender.rb', line 13

def register_templates(templates = nil)
  @templates ||= {} # default_templates
  @templates = @templates.merge!(templates || {})
end

Instance Method Details

#allow_append(txt, context) ⇒ Object



60
61
62
# File 'lib/appenders/base_appender.rb', line 60

def allow_append(txt, context)  
      
end

#handle(txt, context) ⇒ Object

default action handler depending on filters result



52
53
54
55
56
57
58
# File 'lib/appenders/base_appender.rb', line 52

def handle(txt, context)
  if filters_allow?(txt, context)
    allow_append(txt, context)
  else
    not_allow_append(txt, context)
  end
end

#not_allow_append(txt, context) ⇒ Object



64
65
# File 'lib/appenders/base_appender.rb', line 64

def not_allow_append(txt, context)
end

#time_limitObject



67
68
69
# File 'lib/appenders/base_appender.rb', line 67

def time_limit
  options[:time_limit] || 1.minute    
end