Merge pull request #575 from cantino/longer_agent_logs

Add a button to view full error logs; allow longer than 2000 characters

Andrew Cantino vor 10 Jahren
Ursprung
Commit
c0df2352a6

+ 21 - 0
app/assets/javascripts/pages/agent-show-page.js.coffee

@@ -15,6 +15,27 @@ class @AgentShowPage
15 15
     $("#logs .refresh, #logs .clear").hide()
16 16
     $.get "/agents/#{agentId}/logs", (html) =>
17 17
       $("#logs .logs").html html
18
+      $("#logs .logs .show-log-details").each ->
19
+        $button = $(this)
20
+        $button.on 'click', (e) ->
21
+          e.preventDefault()
22
+          $("body").append """
23
+            <div class="modal fade" tabindex="-1" id='dynamic-modal' role="dialog" aria-labelledby="dynamic-modal-label" aria-hidden="true">
24
+              <div class="modal-dialog modal-lg">
25
+                <div class="modal-content">
26
+                  <div class="modal-header">
27
+                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
28
+                    <h4 class="modal-title" id="dynamic-modal-label"></h4>
29
+                  </div>
30
+                  <div class="modal-body"><pre></pre></div>
31
+                </div>
32
+              </div>
33
+            </div>
34
+          """
35
+          $('#dynamic-modal').find('.modal-title').text $button.data('modal-title')
36
+          $('#dynamic-modal').find('.modal-body pre').text $button.data('modal-content')
37
+          $('#dynamic-modal').modal('show').on 'hidden.bs.modal', -> $('#dynamic-modal').remove()
38
+
18 39
       $("#logs .spinner").stop(true, true).fadeOut ->
19 40
         $("#logs .refresh, #logs .clear").show()
20 41
 

+ 8 - 4
app/assets/stylesheets/application.css.scss.erb

@@ -29,15 +29,19 @@ body { padding-top: 60px; }
29 29
 
30 30
 /* Rails scaffold style compatibility */
31 31
 #error_explanation {
32
-  @extend .alert;
33
-  @extend .alert-error;
34
-  @extend .alert-block;
32
+  color: #f00;
33
+  ul {
34
+    list-style: none;
35
+    margin: 0 0 18px 0;
36
+  }
35 37
 }
36 38
 
37 39
 .field_with_errors {
38
-  @extend .control-group.error;
40
+  @extend .has-error;
39 41
 }
40 42
 
43
+.modal-body pre { white-space: pre-wrap; }
44
+
41 45
 .select2 {
42 46
   float: none !important;
43 47
   margin-left: 0 !important;

+ 2 - 2
app/models/agent.rb

@@ -384,7 +384,7 @@ class Agent < ActiveRecord::Base
384 384
         agent.last_receive_at = Time.now
385 385
         agent.save!
386 386
       rescue => e
387
-        agent.error "Exception during receive: #{e.message} -- #{e.backtrace}"
387
+        agent.error "Exception during receive. #{e.message}: #{e.backtrace.join("\n")}"
388 388
         raise
389 389
       end
390 390
     end
@@ -422,7 +422,7 @@ class Agent < ActiveRecord::Base
422 422
         agent.last_check_at = Time.now
423 423
         agent.save!
424 424
       rescue => e
425
-        agent.error "Exception during check: #{e.message} -- #{e.backtrace}"
425
+        agent.error "Exception during check. #{e.message}: #{e.backtrace.join("\n")}"
426 426
         raise
427 427
       end
428 428
     end

+ 1 - 1
app/models/agent_log.rb

@@ -32,6 +32,6 @@ class AgentLog < ActiveRecord::Base
32 32
   protected
33 33
 
34 34
   def truncate_message
35
-    self.message = message[0...2048] if message.present?
35
+    self.message = message[0...10_000] if message.present?
36 36
   end
37 37
 end

+ 1 - 1
app/models/agents/website_agent.rb

@@ -209,7 +209,7 @@ module Agents
209 209
         }
210 210
       end
211 211
     rescue => e
212
-      error e.message
212
+      error "Error when fetching url: #{e.message}\n#{e.backtrace.join("\n")}"
213 213
     end
214 214
 
215 215
     def receive(incoming_events)

+ 3 - 1
app/views/logs/index.html.erb

@@ -3,7 +3,7 @@
3 3
     <tr>
4 4
       <th>Message</th>
5 5
       <th>When</th>
6
-      <th></th>
6
+      <th width="200px"></th>
7 7
     </tr>
8 8
 
9 9
     <% @logs.each do |log| %>
@@ -24,6 +24,8 @@
24 24
             <% else %>
25 25
               <%= link_to 'Event Out', '#', class: "btn btn-default disabled" %>
26 26
             <% end %>
27
+
28
+            <%= link_to 'Details', '#', :class => "btn btn-default show-log-details", :data => { :'modal-title' => log.level >= 4 ? 'Error' : 'Info', :'modal-content' => log.message } %>
27 29
           </div>
28 30
         </td>
29 31
       </tr>

+ 2 - 2
spec/models/agent_log_spec.rb

@@ -44,9 +44,9 @@ describe AgentLog do
44 44
 
45 45
   it "truncates message to a reasonable length" do
46 46
     log = AgentLog.new(:agent => agents(:jane_website_agent), :level => 3)
47
-    log.message = "a" * 3000
47
+    log.message = "a" * 11_000
48 48
     log.save!
49
-    expect(log.message.length).to eq(2048)
49
+    expect(log.message.length).to eq(10_000)
50 50
   end
51 51
 
52 52
   describe "#log_for_agent" do