MrMurano 1.6.0 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/MrMurano/commands/logs.rb +19 -62
- data/lib/MrMurano/makePretty.rb +66 -0
- data/lib/MrMurano/version.rb +1 -1
- data/spec/MakePretties_spec.rb +83 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 809f02a0c7b0aec4e0543cc15ed16de379307e42
|
4
|
+
data.tar.gz: 7f1bab55284fc4515a089c534f6874a09d951187
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66eb7efda3dd5293e9525592dfdf103f6e9d81c10dc0341302eba4f0b3218214a3252cdf4408bf325737f5a483a41af9bacbcb73ecedf54eac67c5e775837de4
|
7
|
+
data.tar.gz: 49bd0d228335166260c33d06eb87e86b23cc2d8ffbc8ad8e34ce3c2fe3837252e58873c1c812a8aa673016ca810b04cab2ebbabe8ae38bfe457dace8e6d1faa7
|
@@ -1,70 +1,19 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'rainbow/ext/string'
|
1
|
+
require 'MrMurano/Solution'
|
2
|
+
require 'MrMurano/makePretty'
|
4
3
|
|
5
4
|
command :logs do |c|
|
6
5
|
c.syntax = %{mr logs [options]}
|
7
6
|
c.description = %{Get the logs for a solution}
|
8
7
|
c.option '-f','--follow', %{Follow logs from server}
|
9
|
-
c.option '--pollrate RATE', Integer, %{Seconds to sleep between polls}
|
10
8
|
c.option('--[no-]color', %{Toggle colorizing of logs}) {
|
11
9
|
Rainbow.enabled = false
|
12
10
|
}
|
13
11
|
c.option '--[no-]pretty', %{Reformat JSON blobs in logs.}
|
14
12
|
c.option '--[no-]localtime', %{Adjust Timestamps to be in local time}
|
13
|
+
c.option '--raw', %{Don't do any formating of the log data}
|
15
14
|
|
16
15
|
c.action do |args,options|
|
17
|
-
options.default :pretty=>true, :localtime=>true, :
|
18
|
-
|
19
|
-
lasttime = ""
|
20
|
-
|
21
|
-
def makePretty(line, options)
|
22
|
-
out=''
|
23
|
-
if line.has_key?(:type) then
|
24
|
-
out << "#{line[:type]} ".upcase.color(:red).background(:aliceblue)
|
25
|
-
end
|
26
|
-
out << "[#{line[:subject]}]".color(:red).background(:aliceblue)
|
27
|
-
out << " "
|
28
|
-
if options.localtime then
|
29
|
-
curtime = Time.at(line[:timestamp]).localtime.to_datetime.iso8601(3)
|
30
|
-
else
|
31
|
-
curtime = Time.at(line[:timestamp]).to_datetime.iso8601(3)
|
32
|
-
end
|
33
|
-
out << curtime.color(:blue)
|
34
|
-
out << ":\n"
|
35
|
-
if line.has_key?(:data) then
|
36
|
-
data = line[:data]
|
37
|
-
|
38
|
-
if data.kind_of?(Hash) and data.has_key?(:request) and data.has_key?(:response) then
|
39
|
-
out << "---------\nrequest:"
|
40
|
-
if options.pretty then
|
41
|
-
ret = JSON.pretty_generate(data[:request]).to_s
|
42
|
-
ret[0] = ret[0].color(:magenta)
|
43
|
-
ret[-1] = ret[-1].color(:magenta)
|
44
|
-
out << ret
|
45
|
-
else
|
46
|
-
out << data[:request].to_json
|
47
|
-
end
|
48
|
-
|
49
|
-
out << "\n---------\nresponse:"
|
50
|
-
if options.pretty then
|
51
|
-
ret = JSON.pretty_generate(data[:response]).to_s
|
52
|
-
ret[0] = ret[0].color(:magenta)
|
53
|
-
ret[-1] = ret[-1].color(:magenta)
|
54
|
-
out << ret
|
55
|
-
else
|
56
|
-
out << data[:response].to_json
|
57
|
-
end
|
58
|
-
|
59
|
-
else
|
60
|
-
out << data.to_s
|
61
|
-
end
|
62
|
-
|
63
|
-
else
|
64
|
-
out << line.to_s
|
65
|
-
end
|
66
|
-
out
|
67
|
-
end
|
16
|
+
options.default :pretty=>true, :localtime=>true, :raw => false
|
68
17
|
|
69
18
|
sol = MrMurano::Solution.new
|
70
19
|
|
@@ -80,11 +29,15 @@ command :logs do |c|
|
|
80
29
|
|
81
30
|
# for all complete JSON blobs, make them pretty.
|
82
31
|
chunk.gsub!(/\{(?>[^}{]+|\g<0>)*\}/m) do |m|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
32
|
+
if options.raw then
|
33
|
+
puts m
|
34
|
+
else
|
35
|
+
js = JSON.parse(m, {:allow_nan=>true,
|
36
|
+
:symbolize_names => true,
|
37
|
+
:create_additions=>false})
|
38
|
+
puts MrMurano::Pretties::makePretty(js, options)
|
39
|
+
end
|
40
|
+
'' #remove (we're kinda abusing gsub here.)
|
88
41
|
end
|
89
42
|
|
90
43
|
# is there an incomplete one?
|
@@ -95,7 +48,7 @@ command :logs do |c|
|
|
95
48
|
end
|
96
49
|
end
|
97
50
|
end
|
98
|
-
rescue Interrupt =>
|
51
|
+
rescue Interrupt => _
|
99
52
|
end
|
100
53
|
|
101
54
|
else
|
@@ -103,7 +56,11 @@ command :logs do |c|
|
|
103
56
|
|
104
57
|
if ret.kind_of?(Hash) and ret.has_key?(:items) then
|
105
58
|
ret[:items].reverse.each do |line|
|
106
|
-
|
59
|
+
if options.raw then
|
60
|
+
puts line
|
61
|
+
else
|
62
|
+
puts MrMurano::Pretties::makePretty(line, options)
|
63
|
+
end
|
107
64
|
end
|
108
65
|
else
|
109
66
|
say_error "Couldn't get logs: #{ret}"
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'json'
|
3
|
+
require 'rainbow/ext/string'
|
4
|
+
|
5
|
+
module MrMurano
|
6
|
+
module Pretties
|
7
|
+
def self.makeJsonPretty(data, options)
|
8
|
+
if options.pretty then
|
9
|
+
ret = JSON.pretty_generate(data).to_s
|
10
|
+
ret[0] = ret[0].color(:magenta)
|
11
|
+
ret[-1] = ret[-1].color(:magenta)
|
12
|
+
ret
|
13
|
+
else
|
14
|
+
data.to_json
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.makePretty(line, options)
|
19
|
+
out=''
|
20
|
+
out << "#{line[:type] || '--'} ".upcase.color(:red).background(:aliceblue)
|
21
|
+
out << "[#{line[:subject] || ''}]".color(:red).background(:aliceblue)
|
22
|
+
out << " "
|
23
|
+
if line.has_key?(:timestamp) then
|
24
|
+
if line[:timestamp].kind_of? Numeric then
|
25
|
+
if options.localtime then
|
26
|
+
curtime = Time.at(line[:timestamp]).localtime.to_datetime.iso8601(3)
|
27
|
+
else
|
28
|
+
curtime = Time.at(line[:timestamp]).to_datetime.iso8601(3)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
curtime = line[:timestamp]
|
32
|
+
end
|
33
|
+
else
|
34
|
+
curtime = "<no timestamp>"
|
35
|
+
end
|
36
|
+
out << curtime.color(:blue)
|
37
|
+
out << ":\n"
|
38
|
+
if line.has_key?(:data) then
|
39
|
+
data = line[:data]
|
40
|
+
|
41
|
+
if data.kind_of?(Hash) then
|
42
|
+
if data.has_key?(:request) and data.has_key?(:response) then
|
43
|
+
out << "---------\nrequest:"
|
44
|
+
out << makeJsonPretty(data[:request], options)
|
45
|
+
|
46
|
+
out << "\n---------\nresponse:"
|
47
|
+
out << makeJsonPretty(data[:response], options)
|
48
|
+
else
|
49
|
+
out << makeJsonPretty(data, options)
|
50
|
+
end
|
51
|
+
else
|
52
|
+
out << data.to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
else
|
56
|
+
line.delete :type
|
57
|
+
line.delete :timestamp
|
58
|
+
line.delete :subject
|
59
|
+
out << makeJsonPretty(line, options)
|
60
|
+
end
|
61
|
+
out
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
# vim: set ai et sw=2 ts=2 :
|
data/lib/MrMurano/version.rb
CHANGED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'MrMurano/version'
|
2
|
+
require 'MrMurano/makePretty'
|
3
|
+
|
4
|
+
RSpec.describe MrMurano::Pretties do
|
5
|
+
before(:example) do
|
6
|
+
@options = {:pretty=>true}
|
7
|
+
def @options.method_missing(mid)
|
8
|
+
self[mid]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "makes json pretty with color" do
|
13
|
+
data ={:type=>"debug", :timestamp=>1476386031,
|
14
|
+
:subject=>"websocket_websocket_info",
|
15
|
+
:data=>"Script Error: "}
|
16
|
+
str ="\e[35m{\e[0m\n \"type\": \"debug\",\n \"timestamp\": 1476386031,\n \"subject\": \"websocket_websocket_info\",\n \"data\": \"Script Error: \"\n\e[35m}\e[0m"
|
17
|
+
ret = MrMurano::Pretties::makeJsonPretty(data, @options)
|
18
|
+
expect(ret).to eq(str)
|
19
|
+
end
|
20
|
+
it "makes json pretty without color" do
|
21
|
+
data ={:type=>"debug", :timestamp=>1476386031,
|
22
|
+
:subject=>"websocket_websocket_info",
|
23
|
+
:data=>"Script Error: "}
|
24
|
+
str ="{\"type\":\"debug\",\"timestamp\":1476386031,\"subject\":\"websocket_websocket_info\",\"data\":\"Script Error: \"}"
|
25
|
+
@options[:pretty] = false
|
26
|
+
ret = MrMurano::Pretties::makeJsonPretty(data, @options)
|
27
|
+
expect(ret).to eq(str)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "makes it pretty." do
|
31
|
+
data ={:type=>"debug", :timestamp=>1476386031,
|
32
|
+
:subject=>"websocket_websocket_info",
|
33
|
+
:data=>"Script Error: "}
|
34
|
+
str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m2016-10-13T14:13:51.000-05:00\e[0m:\nScript Error: "
|
35
|
+
ret = MrMurano::Pretties::makePretty(data, @options)
|
36
|
+
expect(ret).to eq(str)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "makes it pretty; missing type" do
|
40
|
+
data ={:timestamp=>1476386031,
|
41
|
+
:subject=>"websocket_websocket_info",
|
42
|
+
:data=>"Script Error: "}
|
43
|
+
str ="\e[31m\e[48;5;231m-- \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m2016-10-13T14:13:51.000-05:00\e[0m:\nScript Error: "
|
44
|
+
ret = MrMurano::Pretties::makePretty(data, @options)
|
45
|
+
expect(ret).to eq(str)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "makes it pretty; missing timestamp" do
|
49
|
+
data ={:type=>"debug",
|
50
|
+
:subject=>"websocket_websocket_info",
|
51
|
+
:data=>"Script Error: "}
|
52
|
+
str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m<no timestamp>\e[0m:\nScript Error: "
|
53
|
+
ret = MrMurano::Pretties::makePretty(data, @options)
|
54
|
+
expect(ret).to eq(str)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "makes it pretty; missing subject" do
|
58
|
+
data ={:type=>"debug", :timestamp=>1476386031,
|
59
|
+
:data=>"Script Error: "}
|
60
|
+
str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[]\e[0m \e[34m2016-10-13T14:13:51.000-05:00\e[0m:\nScript Error: "
|
61
|
+
ret = MrMurano::Pretties::makePretty(data, @options)
|
62
|
+
expect(ret).to eq(str)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
it "makes it pretty; missing data" do
|
67
|
+
data ={:type=>"debug", :timestamp=>1476386031,
|
68
|
+
:subject=>"websocket_websocket_info"}
|
69
|
+
str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m2016-10-13T14:13:51.000-05:00\e[0m:\n\e[35m{\e[0m\n\e[35m}\e[0m"
|
70
|
+
ret = MrMurano::Pretties::makePretty(data, @options)
|
71
|
+
expect(ret).to eq(str)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "makes it pretty; NAN timestamp" do
|
75
|
+
data ={:type=>"debug", :timestamp => "bob",
|
76
|
+
:subject=>"websocket_websocket_info",
|
77
|
+
:data=>"Script Error: "}
|
78
|
+
str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34mbob\e[0m:\nScript Error: "
|
79
|
+
ret = MrMurano::Pretties::makePretty(data, @options)
|
80
|
+
expect(ret).to eq(str)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
# vim: set ai et sw=2 ts=2 :
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: MrMurano
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Conrad Tadpol Tilstra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -231,11 +231,13 @@ files:
|
|
231
231
|
- lib/MrMurano/commands/timeseries.rb
|
232
232
|
- lib/MrMurano/hash.rb
|
233
233
|
- lib/MrMurano/http.rb
|
234
|
+
- lib/MrMurano/makePretty.rb
|
234
235
|
- lib/MrMurano/verbosing.rb
|
235
236
|
- lib/MrMurano/version.rb
|
236
237
|
- spec/Account-Passwords_spec.rb
|
237
238
|
- spec/ConfigFile_spec.rb
|
238
239
|
- spec/Config_spec.rb
|
240
|
+
- spec/MakePretties_spec.rb
|
239
241
|
- spec/ProductBase_spec.rb
|
240
242
|
- spec/ProductContent_spec.rb
|
241
243
|
- spec/Product_spec.rb
|
@@ -272,6 +274,7 @@ test_files:
|
|
272
274
|
- spec/Account-Passwords_spec.rb
|
273
275
|
- spec/ConfigFile_spec.rb
|
274
276
|
- spec/Config_spec.rb
|
277
|
+
- spec/MakePretties_spec.rb
|
275
278
|
- spec/ProductBase_spec.rb
|
276
279
|
- spec/ProductContent_spec.rb
|
277
280
|
- spec/Product_spec.rb
|