lib/chalk-log/layout.rb in chalk-log-0.1.2 vs lib/chalk-log/layout.rb in chalk-log-0.1.3

- old
+ new

@@ -56,27 +56,26 @@ if data.length > 0 raise Chalk::Log::InvalidArguments.new("Invalid leftover arguments: #{data.inspect}") end - id = action_id pid = Process.pid pretty_print( time: timestamp_prefix(time), level: Chalk::Log::LEVELS[level], - action_id: id, + span: span.to_s, message: message, error: error, info: (info && info.merge(contextual_info || {})) || contextual_info, pid: pid ) end def pretty_print(spec) message = build_message(spec[:message], spec[:info], spec[:error]) - message = tag(message, spec[:time], spec[:pid], spec[:action_id]) + message = tag(message, spec[:time], spec[:pid], spec[:span]) message end def build_message(message, info, error) # Make sure we're not mutating the message that was passed in @@ -151,26 +150,34 @@ dumped = JSON.unsafe_generate(wrapped) else dumped = JSON.generate(wrapped) end - dumped[1...-1] # strip off the brackets we added while array-ifying - end + res = dumped[1...-1] # strip off the brackets we added while array-ifying - def action_id - LSpace[:action_id] + # Bug 6566 in ruby 2.0 (but not 2.1) allows generate() to return an invalid + # string when given invalid unicode input. Manually check for it. + unless res.valid_encoding? + raise ArgumentError.new("invalid byte sequence in UTF-8") + end + + res end def contextual_info LSpace[:'chalk.log.contextual_info'] end - def tag(message, time, pid, action_id) + def span + LSpace[:span] || LSpace[:action_id] + end + + def tag(message, time, pid, span) return message unless configatron.chalk.log.tagging metadata = [] metadata << pid if configatron.chalk.log.pid - metadata << action_id if action_id + metadata << span if span.length > 0 prefix = "[#{metadata.join('|')}] " if metadata.length > 0 if configatron.chalk.log.timestamp prefix = "[#{time}] #{prefix}" end