Class: TangaServices::Logger

Inherits:
Syslog::Logger
  • Object
show all
Defined in:
lib/tanga_services/logger.rb

Overview

Logs json to syslog. Automatically delegates stuff to the syslog logger. Use like:

TangaServices.logger.open('my_application_name')
TangaServices.logger.info({message: "I'm interesting data"})
TangaServices.logger.error({message: "i crashed"})

Class Method Summary collapse

Class Method Details

.application_name=(application_name) ⇒ Object



12
13
14
# File 'lib/tanga_services/logger.rb', line 12

def self.application_name=(application_name)
  @application_name = application_name
end

.debug(hash) ⇒ Object



20
21
22
# File 'lib/tanga_services/logger.rb', line 20

def self.debug(hash)
  log(:debug, hash)
end

.error(hash) ⇒ Object



39
40
41
# File 'lib/tanga_services/logger.rb', line 39

def self.error(hash)
  log(:error, hash)
end

.fatal(hash) ⇒ Object



43
44
45
# File 'lib/tanga_services/logger.rb', line 43

def self.fatal(hash)
  log(:fatal, hash)
end

.info(hash) ⇒ Object



24
25
26
# File 'lib/tanga_services/logger.rb', line 24

def self.info(hash)
  log(:info, hash)
end

.log(level, hash) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/tanga_services/logger.rb', line 47

def self.log(level, hash)
  unless hash.is_a?(Hash)
    hash = { object: hash }
  end

  fail ArgumentError, 'we just log hashes' unless hash.is_a?(Hash)
  data = { level: level, object: hash }
  logger.send(level, data.to_json)
end

.loggerObject



16
17
18
# File 'lib/tanga_services/logger.rb', line 16

def self.logger
  @logger || Syslog::Logger.new((@application_name || 'unknown'), Syslog::LOG_LOCAL7)
end

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



57
58
59
# File 'lib/tanga_services/logger.rb', line 57

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

.warn(hash) ⇒ Object



35
36
37
# File 'lib/tanga_services/logger.rb', line 35

def self.warn(hash)
  log(:warn, hash)
end

.write(message) ⇒ Object Also known as: <<



28
29
30
# File 'lib/tanga_services/logger.rb', line 28

def self.write(message)
  log(:info, message: message)
end