Class: Rack::Bug::LogPanel

Inherits:
Panel
  • Object
show all
Defined in:
lib/rack/bug/panels/log_panel.rb

Defined Under Namespace

Classes: LogEntry

Instance Attribute Summary

Attributes inherited from Panel

#request

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Panel

#after, #before, #call, #has_content?, #initialize, #panel_app, #render

Methods included from Render

#compile, #compile!, #compiled_source, #method_name, #method_name_without_locals, #render_template, #signed_params

Constructor Details

This class inherits a constructor from Rack::Bug::Panel

Class Method Details

.logsObject



35
36
37
# File 'lib/rack/bug/panels/log_panel.rb', line 35

def self.logs
  Thread.current["rack.bug.logs"] ||= []
end

.record(message, log_level) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/rack/bug/panels/log_panel.rb', line 22

def self.record(message, log_level)
  return unless Rack::Bug.enabled?
  return unless message
  Thread.current["rack.bug.logs.start"] ||= Time.now
  timestamp = ((Time.now - Thread.current["rack.bug.logs.start"]) * 1000).to_i
  logs << LogEntry.new(log_level, timestamp, message)
end

.resetObject



30
31
32
33
# File 'lib/rack/bug/panels/log_panel.rb', line 30

def self.reset
  Thread.current["rack.bug.logs"] = []
  Thread.current["rack.bug.logs.start"] = nil
end

Instance Method Details

#contentObject



47
48
49
50
51
# File 'lib/rack/bug/panels/log_panel.rb', line 47

def content
  result = render_template "panels/log", :logs => self.class.logs
  self.class.reset
  return result
end

#headingObject



43
44
45
# File 'lib/rack/bug/panels/log_panel.rb', line 43

def heading
  "Log"
end

#nameObject



39
40
41
# File 'lib/rack/bug/panels/log_panel.rb', line 39

def name
  "log"
end