Module: Logsly::InstanceMethods

Defined in:
lib/logsly.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

delegate all calls to the @logger



77
78
79
# File 'lib/logsly.rb', line 77

def method_missing(method, *args, &block)
  @logger.send(method, *args, &block)
end

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.



47
48
49
# File 'lib/logsly.rb', line 47

def level
  @level
end

#log_typeObject (readonly)

Returns the value of attribute log_type.



47
48
49
# File 'lib/logsly.rb', line 47

def log_type
  @log_type
end

#loggerObject (readonly)

Returns the value of attribute logger.



47
48
49
# File 'lib/logsly.rb', line 47

def logger
  @logger
end

#outputsObject (readonly)

Returns the value of attribute outputs.



47
48
49
# File 'lib/logsly.rb', line 47

def outputs
  @outputs
end

Instance Method Details

#==(other_logger) ⇒ Object



84
85
86
87
88
# File 'lib/logsly.rb', line 84

def ==(other_logger)
  other_logger.log_type == @log_type &&
  other_logger.level    == @level    &&
  other_logger.outputs  == @outputs
end

#file_pathObject



69
70
71
72
73
# File 'lib/logsly.rb', line 69

def file_path
  @file_path ||= if (appender = get_file_appender)
    appender.name if appender.respond_to?(:name)
  end
end

#initialize(log_type, opts = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/logsly.rb', line 49

def initialize(log_type, opts = nil)
  opts ||= {}

  @log_type = log_type.to_s
  @level    = (opts[:level]  || opts['level']   || 'info').to_s
  @outputs  = [*(opts[:outputs] || opts['outputs'] || [])]

  unique_name   = "#{self.class.name}-#{@log_type}-#{self.object_id}"
  @logger       = Logsly::Logging182.logger[unique_name]
  @logger.level = @level

  @outputs.each do |output|
    add_appender(Logsly.outputs(output).to_appender(self))
  end
end

#inspectObject



90
91
92
93
94
95
96
# File 'lib/logsly.rb', line 90

def inspect
  reference = '0x0%x' % (self.object_id << 1)
  "#<#{self.class}:#{reference} "\
  "@log_type=#{@log_type.inspect} "\
  "@level=#{@level.inspect} "\
  "@outputs=#{@outputs.inspect}"
end

#mdc(key, value) ⇒ Object



65
66
67
# File 'lib/logsly.rb', line 65

def mdc(key, value)
  Logsly::Logging182.mdc[key] = value
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/logsly.rb', line 80

def respond_to?(method)
  super || @logger.respond_to?(method)
end