class TN::Logger

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"})

Public Class Methods

<<(message)
Alias for: write
application_name=(application_name) click to toggle source
# File lib/tn/logger.rb, line 12
def self.application_name=(application_name)
  @application_name = application_name
end
debug(hash) click to toggle source
# File lib/tn/logger.rb, line 20
def self.debug(hash)
  log(:debug, hash)
end
error(hash) click to toggle source
# File lib/tn/logger.rb, line 39
def self.error(hash)
  log(:error, hash)
end
fatal(hash) click to toggle source
# File lib/tn/logger.rb, line 43
def self.fatal(hash)
  log(:fatal, hash)
end
info(hash) click to toggle source
# File lib/tn/logger.rb, line 24
def self.info(hash)
  log(:info, hash)
end
log(level, hash) click to toggle source
# File lib/tn/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
logger() click to toggle source
# File lib/tn/logger.rb, line 16
def self.logger
  @logger || Syslog::Logger.new((@application_name || 'unknown'), Syslog::LOG_LOCAL7)
end
method_missing(method, *args, &block) click to toggle source
# File lib/tn/logger.rb, line 57
def self.method_missing(method, *args, &block)
  logger.send(method, *args, &block)
end
warn(hash) click to toggle source
# File lib/tn/logger.rb, line 35
def self.warn(hash)
  log(:warn, hash)
end
write(message) click to toggle source
# File lib/tn/logger.rb, line 28
def self.write(message)
  log(:info, message: message)
end
Also aliased as: <<