lib/logstasher.rb in logstasher-0.6.5 vs lib/logstasher.rb in logstasher-0.7.0

- old
+ new

@@ -114,15 +114,24 @@ Thread.current[:logstasher_custom_fields] = val end def log(severity, msg) if self.logger && self.logger.send("#{severity}?") - event = LogStash::Event.new('@source' => self.source, '@fields' => {:message => msg, :level => severity}, '@tags' => ['log']) - self.logger << event.to_json + "\n" + data = {'level' => severity} + if msg.respond_to?(:to_hash) + data.merge!(msg.to_hash) + else + data['message'] = msg + end + self.logger << build_logstash_event(data, ['log']).to_json + "\n" end end + def build_logstash_event(data, tags) + LogStash::Event.new(data.merge('source' => self.source, 'tags' => tags)) + end + def store if RequestStore.store[STORE_KEY].nil? # Get each store it's own private Hash instance. RequestStore.store[STORE_KEY] = Hash.new { |hash, key| hash[key] = {} } end @@ -154,10 +163,12 @@ end private def new_logger(path) - FileUtils.touch path # prevent autocreate messages in log + if path.is_a? String + FileUtils.touch path # prevent autocreate messages in log + end Logger.new path end end require 'logstasher/railtie' if defined?(Rails)