errlog 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +2 -1
- data/README.md +39 -7
- data/lib/errlog/chain_loggger.rb +9 -0
- data/lib/errlog/constants.rb +7 -1
- data/lib/errlog/context.rb +39 -0
- data/lib/errlog/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17e96f6052645fe7624fcde6a74b51d026cd1411
|
4
|
+
data.tar.gz: bd1de2e4d3b099273b6431e1f960cd799c991a96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50139bfaecb2c2efce08c9e2026c975b5dc5be3c191b5053f5d93db96d2ba8e4b8d2c8b779b73f1332c10062c00a6b549bb69274740157643993e2976b83a3a5
|
7
|
+
data.tar.gz: bbc4e3a5e7736f4df68572c4d3ff020fc263e4be04a38c6a315666c5c5eb34a7f613145178d3fd2ce19e9ab51c760d2b4ae32f668855cb3c8533738938a3f808
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
# Errlog
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
This is a reporting tool tor errlog.co service under development, not yet available fpr public.
|
6
|
-
|
7
|
-
|
8
|
-
The rest is a template for not to type it later on. Please ignore.
|
3
|
+
The Errlog logging client (http://errorlog.co). with rails & delayed_job integrations. See usage details
|
4
|
+
at http://errorlog.co/help/rails. The service is in beta test now.
|
9
5
|
|
10
6
|
|
11
7
|
## Installation
|
@@ -22,9 +18,45 @@ Or install it yourself as:
|
|
22
18
|
|
23
19
|
$ gem install errlog
|
24
20
|
|
21
|
+
More: http://errorlog.co/help/rails
|
22
|
+
|
25
23
|
## Usage
|
26
24
|
|
27
|
-
|
25
|
+
Errlog.configure(...) # visit the link above for help on credentials
|
26
|
+
|
27
|
+
Errlog.protect { |ctx|
|
28
|
+
# Any exception from here will be caught and reported
|
29
|
+
ctx.extra_data = "Anything you want to attach to trace/warning/error report"
|
30
|
+
}
|
31
|
+
|
32
|
+
Errlog.protect_rethrow { |ctx|
|
33
|
+
# Same as above, but the exception will be rethrown
|
34
|
+
}
|
35
|
+
|
36
|
+
Errlog.trace "So far so good"
|
37
|
+
|
38
|
+
# some syntax sugar
|
39
|
+
|
40
|
+
x == y or Errlog.error "Something is wrong" do |ctx|
|
41
|
+
ctx.expected_value = x
|
42
|
+
ctx.real_one = y
|
43
|
+
}
|
44
|
+
|
45
|
+
begin
|
46
|
+
...
|
47
|
+
rescue Exception => e
|
48
|
+
Errlog.context.exception e
|
49
|
+
...
|
50
|
+
end
|
51
|
+
|
52
|
+
logger = Errlog::ChainLogger.new
|
53
|
+
logger.info "This string will be collected"
|
54
|
+
|
55
|
+
|
56
|
+
Consult API docs for more: http://rdoc.info/github/sergeych/errlog/master/frames. Configuration
|
57
|
+
details are available at http://errorlog.co/help/rails
|
58
|
+
|
59
|
+
As the service is under active development, be sure to `bundle update errlog` regularly.
|
28
60
|
|
29
61
|
## Contributing
|
30
62
|
|
data/lib/errlog/chain_loggger.rb
CHANGED
@@ -2,23 +2,32 @@ require 'logger'
|
|
2
2
|
|
3
3
|
module Errlog
|
4
4
|
|
5
|
+
# The chain logger is used to collect data for Errlog context (current context is used)
|
6
|
+
# and optionally pass through logs to previous logger (that's why chain).
|
7
|
+
# Potential problem: you can not bound logger to some context instance so far. Leave
|
8
|
+
# issue at the github if you'll need
|
5
9
|
class ChainLogger < Logger
|
6
10
|
|
11
|
+
# @return previous logger instance if any
|
7
12
|
attr_reader :prev_logger
|
8
13
|
|
14
|
+
# Create instance optionally atop of an existing logger.
|
9
15
|
def initialize prev=nil
|
10
16
|
@prev_logger = prev
|
11
17
|
super(nil)
|
12
18
|
end
|
13
19
|
|
20
|
+
# Set log level
|
14
21
|
def level= l
|
15
22
|
@prev_logger and @prev_logger.level = l
|
16
23
|
end
|
17
24
|
|
25
|
+
# @return current log level
|
18
26
|
def level
|
19
27
|
@prev_logger and @prev_logger.level
|
20
28
|
end
|
21
29
|
|
30
|
+
# Standard add log method, see (Logger#add)
|
22
31
|
def add severity, message = nil, progname = nil
|
23
32
|
message = yield if block_given?
|
24
33
|
@prev_logger and @prev_logger.add(severity, message, progname)
|
data/lib/errlog/constants.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
module Errlog
|
2
|
+
# This module could be extended for easy access to constants and severity test
|
3
|
+
# helpers
|
2
4
|
module Constants
|
3
5
|
|
6
|
+
# @!group severity constants
|
7
|
+
|
4
8
|
ERROR = 100
|
5
9
|
WARNING = 50
|
6
|
-
NOT_FOUND =
|
10
|
+
NOT_FOUND = 49
|
7
11
|
TRACE = 1
|
8
12
|
|
13
|
+
# @!endgroup
|
14
|
+
|
9
15
|
def is_error?(code)
|
10
16
|
code >= ERROR
|
11
17
|
end
|
data/lib/errlog/context.rb
CHANGED
@@ -1,8 +1,22 @@
|
|
1
1
|
require 'hashie'
|
2
2
|
|
3
3
|
module Errlog
|
4
|
+
# Context is a central object in Errlog reporting. It is used to collect and
|
5
|
+
# report necessary data about trace, warning and exception. It also carries
|
6
|
+
# arbitrary extra data you might want to see in the errlog report, you just
|
7
|
+
# assign it to the Context object much like with OpenStruct:
|
8
|
+
#
|
9
|
+
# context = Errlog::clear_context
|
10
|
+
# context.instance_name = 'www143'
|
11
|
+
# # ...
|
12
|
+
# context.trace "Something just happened"
|
4
13
|
class Context < Hashie::Mash
|
5
14
|
|
15
|
+
# Perform a given block rescuing and reporting any uncaught exception.
|
16
|
+
# Exception will not be thrown out of the block:
|
17
|
+
#
|
18
|
+
# @param component_name [String] optional name of the component to report exceptions from
|
19
|
+
# @yieldparam ctx the context itself
|
6
20
|
def protect component_name=nil, options={}
|
7
21
|
component_name and self.component_name = component_name
|
8
22
|
begin
|
@@ -13,35 +27,58 @@ module Errlog
|
|
13
27
|
end
|
14
28
|
end
|
15
29
|
|
30
|
+
# Perform a given block reporting and rethrowing any uncaught exception (see #protect)
|
16
31
|
def protect_rethrow component_name=nil, &block
|
17
32
|
self.protect component_name, retrhow: true, &block
|
18
33
|
end
|
19
34
|
|
35
|
+
# Report exception.
|
36
|
+
#
|
37
|
+
# @param [Exception] e exception to report
|
38
|
+
# @param [Integer] severity severity to report, some exceptions mught be useful to report as warnings or
|
39
|
+
# even traces.
|
40
|
+
# @yieldparam context the context itself, you can set more fields in a block
|
41
|
+
# @note that exception reports its class and backtrace, so there is no need to provide details
|
20
42
|
def exception e, severity=Errlog::ERROR, &block
|
21
43
|
self.stack = e.backtrace
|
22
44
|
self.exception_class = e.class.name
|
23
45
|
report e.to_s, severity
|
24
46
|
end
|
25
47
|
|
48
|
+
# Report trace. There is a syntax sugar to provide extra information in the block where the context
|
49
|
+
# is passed as the parameter:
|
50
|
+
#
|
51
|
+
# everything_is_ok or context.trace "Not all is ok" do |ctx|
|
52
|
+
# ctx.valuable_data = some_value
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# Reporting methods except #exception uses the caller's stack in the report.
|
26
56
|
def trace text, details=nil, severity=Errlog::TRACE, &block
|
27
57
|
details and self.details = details
|
28
58
|
report text, severity
|
29
59
|
end
|
30
60
|
|
61
|
+
# Report a warning, see {#trace}
|
31
62
|
def warning text, details=nil, severity=Errlog::WARNING, &block
|
32
63
|
details and self.details = details
|
33
64
|
report text, severity
|
34
65
|
end
|
35
66
|
|
67
|
+
# Report an error, see {#trace}
|
36
68
|
def error text, details=nil, severity=Errlog::ERROR, &block
|
37
69
|
details and self.details = details
|
38
70
|
report text, severity, &block
|
39
71
|
end
|
40
72
|
|
73
|
+
# Add a handler that will be called with a context as the sole parameter before reporting.
|
74
|
+
# If the context will not be user for reporting, the handler will not be called. Use it
|
75
|
+
# to collect additional information that won't be needed otherwise, especially if collecting takes
|
76
|
+
# significant resources.
|
41
77
|
def before_report &block
|
42
78
|
(@before_handlers ||= []) << block
|
43
79
|
end
|
44
80
|
|
81
|
+
# Report test with e given severity. See #{trace} for optional block usage.
|
45
82
|
def report text, severity = Errlog::ERROR
|
46
83
|
yield self if block_given?
|
47
84
|
|
@@ -67,8 +104,10 @@ module Errlog
|
|
67
104
|
end
|
68
105
|
end
|
69
106
|
|
107
|
+
# @private
|
70
108
|
MAX_LOG_LINES = 100
|
71
109
|
|
110
|
+
# @private
|
72
111
|
def add_log_record record
|
73
112
|
@log_records ||= []
|
74
113
|
@log_records << record
|
data/lib/errlog/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: errlog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergeych
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: boss-protocol
|
@@ -149,3 +149,4 @@ test_files:
|
|
149
149
|
- spec/errlog_spec.rb
|
150
150
|
- spec/packager_spec.rb
|
151
151
|
- spec/spec_helper.rb
|
152
|
+
has_rdoc:
|