Module: Logsly::InstanceMethods

Defined in:
lib/logsly.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.



50
51
52
# File 'lib/logsly.rb', line 50

def level
  @level
end

#log_typeObject (readonly)

Returns the value of attribute log_type.



50
51
52
# File 'lib/logsly.rb', line 50

def log_type
  @log_type
end

#output_loggersObject (readonly)

Returns the value of attribute output_loggers.



50
51
52
# File 'lib/logsly.rb', line 50

def output_loggers
  @output_loggers
end

#outputsObject (readonly)

Returns the value of attribute outputs.



50
51
52
# File 'lib/logsly.rb', line 50

def outputs
  @outputs
end

Instance Method Details

#==(other_logger) ⇒ Object



103
104
105
106
107
# File 'lib/logsly.rb', line 103

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

#appendersObject



99
100
101
# File 'lib/logsly.rb', line 99

def appenders
  @appenders ||= self.output_loggers.map{ |(_, l)| l.appenders }.flatten
end

#file_pathObject



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

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

#initialize(log_type, opts = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/logsly.rb', line 52

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

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

  @output_loggers = @outputs.inject({}) do |hash, output_name|
    unique_name = "#{self.class.name}-#{@log_type}-#{self.object_id}-#{output_name}"
    logger      = Logsly::Logging182.logger[unique_name]
    output      = Logsly.outputs(output_name)
    output_data = output.data(self)

    # prefer output-specific level; fall back to general level
    logger.level = output_data ? output_data.level : @level
    add_appender(logger, output.to_appender(output_data))

    hash[output_name] = logger
    hash
  end
end

#inspectObject



109
110
111
112
113
114
115
# File 'lib/logsly.rb', line 109

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



74
75
76
# File 'lib/logsly.rb', line 74

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