Sha256: f8e3225b9dfac546df18d147a74ea553b71f90c1bc0e3211c8fc3154eac3bf03
Contents?: true
Size: 1.8 KB
Versions: 4
Compression:
Stored size: 1.8 KB
Contents
module GELF # Methods for compatibility with Ruby Logger. module LoggerCompatibility # Does nothing. def close end # Use it like Logger#add… or better not to use at all. def add(level, *args) raise ArgumentError.new('Wrong arguments.') unless (0..2).include?(args.count) # Ruby Logger's author is a maniac. message, facility = if args.count == 2 [args[0], args[1]] elsif args.count == 0 [yield, nil] elsif block_given? [yield, args[0]] else [args[0], nil] end hash = {'short_message' => message, 'facility' => facility} hash.merge!(self.class.extract_hash_from_exception(message)) if message.is_a?(Exception) notify_with_level(level, hash) end # Redefines methods in +Notifier+. GELF::Levels.constants.each do |const| class_eval <<-EOT, __FILE__, __LINE__ + 1 def #{const.downcase}(*args) # def debug(*args) args.unshift(yield) if block_given? # args.unshift(yield) if block_given? add(GELF::#{const}, *args) # add(GELF::DEBUG, *args) end # end def #{const.downcase}? # def debug? GELF::#{const} >= level # GELF::DEBUG >= level end # end EOT end def <<(message) notify('short_message' => message, 'level' => GELF::UNKNOWN) end end # Graylog2 notifier, compatible with Ruby Logger. class Logger < Notifier include LoggerCompatibility @last_chunk_id = 0 end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
gelf-1.1.3 | lib/gelf/logger.rb |
gelf-1.1.1 | lib/gelf/logger.rb |
gelf-1.1.0 | lib/gelf/logger.rb |
gelf-1.1.0.rc1 | lib/gelf/logger.rb |