Module: Errlog

Extended by:
Constants
Includes:
Constants
Defined in:
lib/errlog.rb,
lib/errlog/context.rb,
lib/errlog/version.rb,
lib/errlog/packager.rb,
lib/errlog/constants.rb,
lib/errlog/chain_loggger.rb,
lib/errlog/rails_controller_extensions.rb

Overview

The reporting module for errlog service, see errorlog.com for details.

The usage is quite simple:

Errlog.configure(
    , ,
    :application => 'MyGreatApplication')

And use any of {Errlog.context} and {Errlog::Context} methods to report exceptions,
collect logs, traces and so on.

See http://errorlog.co/help for more.

Defined Under Namespace

Modules: Constants, ControllerFilter Classes: ChainLogger, Context, ContextMiddleware, Packager, Railtie

Constant Summary collapse

VERSION =
"0.3.8"
@@configured =
false
@@send_error =
false

Constants included from Constants

Constants::ERROR, Constants::NOT_FOUND, Constants::STAT_DATA, Constants::TRACE, Constants::WARNING

Class Method Summary collapse

Methods included from Constants

is_error?, is_trace?, is_warning?, severity_name

Class Method Details

.applicationObject



94
95
96
# File 'lib/errlog.rb', line 94

def self.application
  @@application #rescue nil
end

.clear_contextObject



154
155
156
157
158
# File 'lib/errlog.rb', line 154

def self.clear_context
  ctx                             = Errlog::Context.new
  Thread.current[:errlog_context] = ctx
  ctx
end

.configure(id, key, opts = {}) ⇒ Object

Configure your instance. Sbhould be called before any other methods. Follow errorlog.co/help/rails to get your credentials

Parameters:

  • id (string)

    account id



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/errlog.rb', line 50

def self.configure id, key, opts={}
  @@configured                     = true
  @@app_id, @@app_secret, @options = id, key, opts
  @@application                    = opts[:application] || ''
  @@packager                       = packager @@app_id, @@app_secret
  @@host                           = opts[:host] || "http://errorlog.co"
  @@client                         = HTTPClient.new
  @@opts                           = opts
  @@rails                          = defined?(Rails)
  @@loggers_ready                  = false
  @@component                      = nil

  if @@rails && !opts[:no_catch_logs]
    if Rails.env != 'test'
      @@logger                      = Rails.logger = ChainLogger.new Rails.logger
      ActionController::Base.logger = ChainLogger.new ActionController::Base.logger
      if defined?(ActiveRecord)
        ActiveRecord::Base.logger = ChainLogger.new ActiveRecord::Base.logger
      end
    end
    @@loggers_ready = true

    # Delayed job
    if defined?(Delayed)
      require 'errlog/dj'
    end
  end
end

.configured?Boolean

Returns:

  • (Boolean)


98
99
100
101
102
103
104
# File 'lib/errlog.rb', line 98

def self.configured?
  if @@configured
    (@@rails && Rails.env == 'test') || defined?(@@app_id) && @@app_id && @@app_secret
  else
    false
  end
end

.contextObject



160
161
162
# File 'lib/errlog.rb', line 160

def self.context
  Thread.current[:errlog_context] || clear_context
end

.default_packagerObject



122
123
124
# File 'lib/errlog.rb', line 122

def self.default_packager
  @@packager
end

.default_platformObject



106
107
108
# File 'lib/errlog.rb', line 106

def self.default_platform
  @@rails ? 'rails' : 'ruby'
end

.error(text, details = nil, severity = Errlog::TRACE, &block) ⇒ Object



142
143
144
# File 'lib/errlog.rb', line 142

def self.error text, details=nil, severity=Errlog::TRACE, &block
  self.context.error text, details, severity, &block
end

.exception(e, &block) ⇒ Object



134
135
136
# File 'lib/errlog.rb', line 134

def self.exception e, &block
  self.context.exception e, &block
end

.logger(logger = nil) ⇒ ChainLogger

Create logger that will report its content on error, trace and warning and ErrlogContext reporting funtions. It can user existing logger to pass through, ot will create Logger with STDOUT

Parameters:

  • logger (defaults to: nil)

    existing logger to pass log to, If nil, STDOUT Logger will be created

Returns:



85
86
87
88
# File 'lib/errlog.rb', line 85

def self.logger logger = nil
  logger ||= Logger.new(STDOUT)
  @@logger ||= ChainLogger.new logger
end

.pack(data) ⇒ Object



118
119
120
# File 'lib/errlog.rb', line 118

def self.pack data
  @@packager.pack(data)
end

.packager(id, key) ⇒ Errlog::Packager

Returns packager instance for configured credentials, see Errorlog.configure.

Returns:

  • (Errlog::Packager)

    packager instance for configured credentials, see Errorlog.configure



39
40
41
# File 'lib/errlog.rb', line 39

def self.packager id, key
  return Packager.new id, key
end

.protect(component_name = nil, options = {}, &block) ⇒ Object



126
127
128
# File 'lib/errlog.rb', line 126

def self.protect component_name=nil, options={}, &block
  context.protect component_name, options, &block
end

.protect_rethrow(component_name = nil, &block) ⇒ Object



130
131
132
# File 'lib/errlog.rb', line 130

def self.protect_rethrow component_name=nil, &block
  context.protect_rethrow component_name, &block
end

.rails?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/errlog.rb', line 110

def self.rails?
  @@rails
end

.rails_test?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/errlog.rb', line 114

def self.rails_test?
  @rails_test == nil and @rails_test = @@rails && Rails.env == 'test'
end

.report(text, severity = Errlog::ERROR, &block) ⇒ Object



150
151
152
# File 'lib/errlog.rb', line 150

def self.report text, severity = Errlog::ERROR, &block
  self.context.report text, severity, &block
end

.trace(text, details = nil, severity = Errlog::TRACE, &block) ⇒ Object



138
139
140
# File 'lib/errlog.rb', line 138

def self.trace text, details=nil, severity=Errlog::TRACE, &block
  self.context.trace text, details, severity, &block
end

.use_logging?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/errlog.rb', line 90

def self.use_logging?
  !@@opts[:no_logs]
end

.waitObject



164
165
166
167
168
# File 'lib/errlog.rb', line 164

def self.wait
  @@send_threads.each { |t| t.weakref_alive? and t.join }
  @@send_threads == []
  @@send_error
end

.warning(text, details = nil, severity = Errlog::TRACE, &block) ⇒ Object



146
147
148
# File 'lib/errlog.rb', line 146

def self.warning text, details=nil, severity=Errlog::TRACE, &block
  self.context.warning text, details, severity, &block
end