nightwatch 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd1fc2ef1a0a7142a9dd3fe84f9a9c1c3fbfdc7a
4
- data.tar.gz: 4b9405f153268d28a57dd10a1b8e4c9c80a8d707
3
+ metadata.gz: bf08834a8450c61d19d81eae776ed3894d815292
4
+ data.tar.gz: 746969a1c82a7564e5ca70216cf4349a64728404
5
5
  SHA512:
6
- metadata.gz: 107a9bb6fdaef1271c99f41ad97040d531a27bb2c253366c1f6a4063fc2d46a169f695ce4b29e93a2c93c094b669302ee11059ed55ace1e5e64e9f131c4d5fac
7
- data.tar.gz: 2447b55861efc37c95f59557f7d3592dc8f70bfd28165e746978b5a5e16962b2b33614c237da60f44b565b915df01ab5bcbb6cdf7197249f6e3e82519814c41d
6
+ metadata.gz: 2b43abaaf82b85772e5b1c548c7022a7a367252d81025817b5b87514fc243029e24af854f1564efd4244a526f7727c9db1e118e2abeaef879f8ced363be8cb32
7
+ data.tar.gz: 6747d65e6c10b13d756fc186b3f0c34e5a3e1ed549ad00ca7340057658b1b25020490da7e1adb2ff971d9951f2207cabea98930668ba74fb6be44e82c0b85f22
@@ -1 +1,3 @@
1
1
  require 'nightwatch/monitor'
2
+ require 'nightwatch/configuration'
3
+ require 'nightwatch/mongo'
@@ -0,0 +1,18 @@
1
+ require 'singleton'
2
+ require 'nightwatch/mongo'
3
+
4
+ module Nightwatch
5
+ def self.configure(&block)
6
+ Configuration.instance.instance_eval(&block)
7
+ end
8
+
9
+ class Configuration
10
+ include Singleton
11
+
12
+ def initialize
13
+ @logger = Mongo.new
14
+ end
15
+
16
+ attr_accessor :logger
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ require 'mongo'
2
+
3
+ module Nightwatch
4
+ class Mongo
5
+ def initialize(opts = {})
6
+ @host = opts[:host] || '127.0.0.1'
7
+ @port = opts[:port] || 27017
8
+ @database = opts[:database] || 'nightwatch'
9
+ end
10
+
11
+ def log(record)
12
+ collection.insert(record)
13
+ end
14
+
15
+ private
16
+
17
+ def collection
18
+ @collection ||= begin
19
+ mongo = ::Mongo::MongoClient.new(@host, @port)
20
+ mongo[@database]['exceptions']
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,75 +1,76 @@
1
- require 'mongo'
2
1
  require 'socket'
2
+ require 'singleton'
3
+ require 'nightwatch/configuration'
3
4
 
4
- class ExceptionManager
5
- def self.instance
6
- @@manager ||= ExceptionManager.new
7
- end
8
-
9
- def self.absolute_path(file)
10
- File.absolute_path(file).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
11
- end
5
+ module Nightwatch
6
+ class ExceptionManager
7
+ include Singleton
12
8
 
13
- @@argv = Array.new(ARGV)
14
- @@script = absolute_path($0)
15
-
16
- def initialize
17
- @exceptions = {}
18
- end
9
+ def self.absolute_path(file)
10
+ File.absolute_path(file).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
11
+ end
19
12
 
20
- def add_exception(exception)
21
- @exceptions[exception.object_id] = [exception, stack(exception), Time.now.to_i]
22
- end
13
+ @@argv = Array.new(ARGV)
14
+ @@script = absolute_path($0)
23
15
 
24
- def commit!
25
- # Support other connection endpoints
26
- mongo = Mongo::MongoClient.new
27
- collection = mongo['nightwatch']['exceptions']
28
- host = Socket.gethostname
29
- env = Hash[ENV.to_a]
30
-
31
- @exceptions.each do |id, info|
32
- exception, stack, ticks = info
33
- klass = exception.class.name
34
-
35
- collection.insert({
36
- pid: $$,
37
- script: @@script,
38
- argv: @@argv,
39
- env: env,
40
- host: host,
41
- class: klass,
42
- message: exception.to_s,
43
- stack: stack,
44
- timestamp: ticks
45
- })
16
+ def initialize
17
+ @exceptions = {}
18
+ @config = Configuration.instance
46
19
  end
47
- end
48
20
 
49
- private
21
+ def add_exception(exception)
22
+ @exceptions[exception.object_id] = [exception, stack(exception), Time.now.to_i]
23
+ end
50
24
 
51
- def stack(exception)
52
- stack = []
53
- if exception.respond_to? :backtrace_locations
54
- exception.backtrace_locations.each do |location|
55
- stack << {
56
- label: location.label,
57
- path: self.class.absolute_path(location.absolute_path),
58
- line: location.lineno
59
- }
60
- end
61
- else
62
- exception.backtrace.each do |location|
63
- location.match(/^(.+?):(\d+)(|:in `(.+)')$/)
64
- stack << {
65
- label: $4,
66
- path: self.class.absolute_path($1),
67
- line: $2.to_i
25
+ def commit!
26
+ host = Socket.gethostname
27
+ env = Hash[ENV.to_a]
28
+
29
+ @exceptions.each do |id, info|
30
+ exception, stack, ticks = info
31
+ klass = exception.class.name
32
+
33
+ record = {
34
+ pid: $$,
35
+ script: @@script,
36
+ argv: @@argv,
37
+ env: env,
38
+ host: host,
39
+ class: klass,
40
+ message: exception.to_s,
41
+ stack: stack,
42
+ timestamp: ticks
68
43
  }
44
+
45
+ @config.logger.log(record)
69
46
  end
70
47
  end
71
48
 
72
- stack
49
+ private
50
+
51
+ def stack(exception)
52
+ stack = []
53
+ if exception.respond_to? :backtrace_locations
54
+ exception.backtrace_locations.each do |location|
55
+ stack << {
56
+ label: location.label,
57
+ path: self.class.absolute_path(location.absolute_path),
58
+ line: location.lineno
59
+ }
60
+ end
61
+ else
62
+ exception.backtrace.each do |location|
63
+ location.match(/^(.+?):(\d+)(|:in `(.+)')$/)
64
+ stack << {
65
+ label: $4,
66
+ path: self.class.absolute_path($1),
67
+ line: $2.to_i
68
+ }
69
+ end
70
+ end
71
+
72
+ stack
73
+ end
73
74
  end
74
75
  end
75
76
 
@@ -82,7 +83,7 @@ class Thread
82
83
  orig_block.call
83
84
  ensure
84
85
  if $!
85
- ExceptionManager.instance.add_exception($!)
86
+ Nightwatch::ExceptionManager.instance.add_exception($!)
86
87
  end
87
88
  end
88
89
  end
@@ -93,8 +94,8 @@ end
93
94
 
94
95
  at_exit do
95
96
  if $!
96
- ExceptionManager.instance.add_exception($!)
97
+ Nightwatch::ExceptionManager.instance.add_exception($!)
97
98
  end
98
99
 
99
- ExceptionManager.instance.commit!
100
+ Nightwatch::ExceptionManager.instance.commit!
100
101
  end
@@ -1,3 +1,3 @@
1
1
  module Nightwatch
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -38,11 +38,12 @@ html, body {
38
38
  .tile .support {
39
39
  padding: 10px 15px;
40
40
  }
41
- .exception h1 {
41
+ .exception h5 {
42
42
  font-size: 18px;
43
43
  font-weight: normal;
44
44
  margin: 0;
45
45
  padding: 0;
46
+ line-height: 120%;
46
47
  text-overflow: ellipsis;
47
48
  overflow: hidden;
48
49
  white-space: nowrap;
@@ -62,6 +63,7 @@ html, body {
62
63
  padding: 20px 30px 10px 30px;
63
64
  }
64
65
  .exception-details h4 {
66
+ line-height: 120%;
65
67
  text-overflow: ellipsis;
66
68
  overflow: hidden;
67
69
  white-space: nowrap;
@@ -111,5 +113,8 @@ html, body {
111
113
  font-weight: 500;
112
114
  }
113
115
  .none {
114
- color: #999;
116
+ color: #aaa;
117
+ }
118
+ .location {
119
+ font-family: Consolas, Monaco, monospace;
115
120
  }
@@ -41,7 +41,7 @@
41
41
  <ul class="exceptions">
42
42
  <li ng-class="{ tile: true, exception: true, active: isActive(exception) }" ng-click="setActive(exception)" ng-repeat="exception in exceptions | exceptionFilter: { class: exceptionClass } | orderBy:'-timestamp'">
43
43
  <div class="primary">
44
- <h1><span class="class">{{exception.class}}</span><span ng-if="exception.message != exception.class">: <span class="message">{{exception.message}}</span></span></h1>
44
+ <h5><span class="class">{{exception.class}}</span><span ng-if="exception.message != exception.class">: <span class="message">{{exception.message}}</span></span></h5>
45
45
  </div>
46
46
  <div class="support">
47
47
  <span class="host">{{exception.host}}</span>
@@ -70,7 +70,7 @@
70
70
  </div>
71
71
  <div class="row">
72
72
  <div class="col-md-2"><p class="name">Location</p></div>
73
- <div class="col-md-10"><p>{{activeException.stack[0].label}} in {{activeException.stack[0].path | basename}}:{{activeException.stack[0].line}}</p></div>
73
+ <div class="col-md-10"><p><span class="location">{{activeException.stack[0].label}}</span> in {{activeException.stack[0].path | basename}}:{{activeException.stack[0].line}}</p></div>
74
74
  </div>
75
75
  <div class="row">
76
76
  <div class="col-md-2"><p class="name">Script</p></div>
@@ -102,7 +102,7 @@
102
102
  <th>Line</th>
103
103
  </tr>
104
104
  <tr ng-repeat="frame in activeException.stack">
105
- <td>{{frame.label}}</td>
105
+ <td><span class="location">{{frame.label}}</span></td>
106
106
  <td>{{frame.path}}</td>
107
107
  <td>{{frame.line}}</td>
108
108
  </tr>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nightwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schmich
@@ -101,6 +101,8 @@ executables:
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - lib/nightwatch/configuration.rb
105
+ - lib/nightwatch/mongo.rb
104
106
  - lib/nightwatch/monitor.rb
105
107
  - lib/nightwatch/version.rb
106
108
  - lib/nightwatch/web/cli.rb