Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow data field to be nil for prettifier

  • Loading branch information...
commit 60f66350c41cb460480dab43ff7e19871424d092 1 parent 5c68aa0
Pieter Noordhuis pietern authored
Showing with 21 additions and 3 deletions.
  1. +16 −3 lib/steno/json_prettifier.rb
  2. +5 −0 spec/unit/json_prettifier_spec.rb
19 lib/steno/json_prettifier.rb
View
@@ -5,10 +5,19 @@
module Steno
end
-# Transforms JSON log lines into a more human readable format
class Steno::JsonPrettifier
- FIELD_ORDER = %w[timestamp source process_id thread_id fiber_id location data
- log_level message]
+ FIELD_ORDER = %w[
+ timestamp
+ source
+ process_id
+ thread_id
+ fiber_id
+ location
+ data
+ log_level
+ message
+ ]
+
MIN_COL_WIDTH = 14
class ParseError < StandardError
@@ -98,6 +107,10 @@ def format_location(record)
"%s/%s:%s" % [trimmed_filename, record["method"], record["lineno"]]
end
+ def check_data(record)
+ record["data"].is_a?(Hash)
+ end
+
def format_data(record)
record["data"].map { |k, v| "#{k}=#{v}" }.join(",")
end
5 spec/unit/json_prettifier_spec.rb
View
@@ -75,5 +75,10 @@
prettifier.prettify_line("blah")
}.to raise_error(Steno::JsonPrettifier::ParseError)
end
+
+ it "should work with a nil data field" do
+ line = prettifier.prettify_line(%@{"data":null}@)
+ line.should include(" - ")
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.