lib/tanga_services/logger.rb in tanga_services-0.0.8 vs lib/tanga_services/logger.rb in tanga_services-0.0.9
- old
+ new
@@ -8,15 +8,15 @@
# TangaServices.logger.open('my_application_name')
# TangaServices.logger.info({message: "I'm interesting data"})
# TangaServices.logger.error({message: "i crashed"})
class Logger < Syslog::Logger
def self.application_name=(application_name)
- @logger ||= Syslog::Logger.new(application_name, Syslog::LOG_LOCAL7)
+ @application_name = application_name
end
def self.logger
- @logger
+ @logger || Syslog::Logger.new((@application_name || 'unknown'), Syslog::LOG_LOCAL7)
end
def self.debug(hash)
log(:debug, hash)
end
@@ -43,17 +43,16 @@
def self.fatal(hash)
log(:fatal, hash)
end
def self.log(level, hash)
- fail ArgumentError, 'must have application_name set' unless @logger
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)
+ logger.send(level, data.to_json)
end
def self.method_missing(method, *args, &block)
logger.send(method, *args, &block)
end