Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow data field to be nil for prettifier

  • Loading branch information...
commit 60f66350c41cb460480dab43ff7e19871424d092 1 parent 5c68aa0
Pieter Noordhuis pietern authored
19 lib/steno/json_prettifier.rb
@@ -5,10 +5,19 @@
5 5 module Steno
6 6 end
7 7
8   -# Transforms JSON log lines into a more human readable format
9 8 class Steno::JsonPrettifier
10   - FIELD_ORDER = %w[timestamp source process_id thread_id fiber_id location data
11   - log_level message]
  9 + FIELD_ORDER = %w[
  10 + timestamp
  11 + source
  12 + process_id
  13 + thread_id
  14 + fiber_id
  15 + location
  16 + data
  17 + log_level
  18 + message
  19 + ]
  20 +
12 21 MIN_COL_WIDTH = 14
13 22
14 23 class ParseError < StandardError
@@ -98,6 +107,10 @@ def format_location(record)
98 107 "%s/%s:%s" % [trimmed_filename, record["method"], record["lineno"]]
99 108 end
100 109
  110 + def check_data(record)
  111 + record["data"].is_a?(Hash)
  112 + end
  113 +
101 114 def format_data(record)
102 115 record["data"].map { |k, v| "#{k}=#{v}" }.join(",")
103 116 end
5 spec/unit/json_prettifier_spec.rb
@@ -75,5 +75,10 @@
75 75 prettifier.prettify_line("blah")
76 76 }.to raise_error(Steno::JsonPrettifier::ParseError)
77 77 end
  78 +
  79 + it "should work with a nil data field" do
  80 + line = prettifier.prettify_line(%@{"data":null}@)
  81 + line.should include(" - ")
  82 + end
78 83 end
79 84 end

0 comments on commit 60f6635

Please sign in to comment.
Something went wrong with that request. Please try again.