Class: GrayLogger::Logger

Inherits:
GELF::Logger
  • Object
show all
Includes:
Support
Defined in:
lib/gray_logger/logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support

included

Constructor Details

#initialize(configuration) ⇒ Logger

Returns a new instance of Logger.



10
11
12
13
14
15
16
17
18
19
# File 'lib/gray_logger/logger.rb', line 10

def initialize(configuration)
  if configuration.valid?
    super(configuration.host, configuration.port, configuration.size, configuration.options)
    @configuration = configuration
  else
    self.disable # from GELF
  end

  @buckets = {}
end

Instance Attribute Details

#bucketsObject (readonly)

Returns the value of attribute buckets.



8
9
10
# File 'lib/gray_logger/logger.rb', line 8

def buckets
  @buckets
end

#configurationObject (readonly)

Returns the value of attribute configuration.



8
9
10
# File 'lib/gray_logger/logger.rb', line 8

def configuration
  @configuration
end

Instance Method Details

#after_request_logObject

logger.after_request_log << => ‘field content’ logger.after_request_log.my_field = ‘field content’



32
33
34
# File 'lib/gray_logger/logger.rb', line 32

def after_request_log
  bucket(:_request)
end

#automatic_logging?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/gray_logger/logger.rb', line 26

def automatic_logging?
  configuration.automatic_logging?
end

#bucket(name) ⇒ Object

logger.bucket(:my_bucket) << => ‘field content’ logger.bucket(:my_bucket).my_field = ‘field content’



38
39
40
# File 'lib/gray_logger/logger.rb', line 38

def bucket(name)
  @buckets[name.to_sym] ||= GrayLogger::Bucket.new
end

#flushObject

flush all buckets



43
44
45
46
47
48
# File 'lib/gray_logger/logger.rb', line 43

def flush
  @buckets.keys.each do |bucket_name|
    flush_bucket(bucket_name)
  end
  reset!
end

#flush_bucket(name) ⇒ Object

flush a specific bucket



51
52
53
54
55
56
# File 'lib/gray_logger/logger.rb', line 51

def flush_bucket(name)
  return false if get_bucket(name).nil?
  message = get_bucket(name).to_message(name)
  self.notify!(message)
  @buckets.delete(name.to_sym)
end

#log_exception(exception) ⇒ Object



58
59
60
61
62
63
# File 'lib/gray_logger/logger.rb', line 58

def log_exception(exception)
  if exception
    after_request_log.short_message = "Error: #{exception}"
    after_request_log.exception_backtrace = exception.backtrace.join("\n")
  end
end

#reset!Object



21
22
23
24
# File 'lib/gray_logger/logger.rb', line 21

def reset!
  @buckets = {}
  self
end