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(
account_id, account_secret,
: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
-
.application ⇒ Object
-
.clear_context ⇒ Object
-
.configure(id, key, opts = {}) ⇒ Object
-
.configured? ⇒ Boolean
-
.context ⇒ Object
-
.default_packager ⇒ Object
-
.default_platform ⇒ Object
-
.error(text, details = nil, severity = Errlog::TRACE, &block) ⇒ Object
-
.exception(e, &block) ⇒ Object
-
.logger(logger = nil) ⇒ ChainLogger
-
.pack(data) ⇒ Object
-
.packager(id, key) ⇒ Errlog::Packager
Packager instance for configured credentials, see Errorlog.configure.
-
.protect(component_name = nil, options = {}, &block) ⇒ Object
-
.protect_rethrow(component_name = nil, &block) ⇒ Object
-
.rails? ⇒ Boolean
-
.rails_test? ⇒ Boolean
-
.report(text, severity = Errlog::ERROR, &block) ⇒ Object
-
.trace(text, details = nil, severity = Errlog::TRACE, &block) ⇒ Object
-
.use_logging? ⇒ Boolean
-
.wait ⇒ Object
-
.warning(text, details = nil, severity = Errlog::TRACE, &block) ⇒ Object
Methods included from Constants
is_error?, is_trace?, is_warning?, severity_name
Class Method Details
.application ⇒ Object
94
95
96
|
# File 'lib/errlog.rb', line 94
def self.application
@@application
end
|
.clear_context ⇒ Object
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 your instance. Sbhould be called before any other methods. Follow errorlog.co/help/rails to get your credentials
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
if defined?(Delayed)
require 'errlog/dj'
end
end
end
|
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
|
.context ⇒ Object
160
161
162
|
# File 'lib/errlog.rb', line 160
def self.context
Thread.current[:errlog_context] || clear_context
end
|
.default_packager ⇒ Object
122
123
124
|
# File 'lib/errlog.rb', line 122
def self.default_packager
@@packager
end
|
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
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
|
Returns 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
110
111
112
|
# File 'lib/errlog.rb', line 110
def self.rails?
@@rails
end
|
.rails_test? ⇒ 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
90
91
92
|
# File 'lib/errlog.rb', line 90
def self.use_logging?
!@@opts[:no_logs]
end
|
.wait ⇒ Object
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
|