catcher 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +11 -9
- data/lib/catcher.rb +10 -0
- data/lib/catcher/version.rb +1 -1
- metadata +14 -16
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 35185a4122f8bbaf1d3d1b04f252ff74049b29e0
|
4
|
+
data.tar.gz: 6a0811eb41b0c0b6e40d43fefbd1ba0c15490228
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f95e639bfd27e8efd9c00515806300bffd10240f75cf4acaec754e59dd803cd5f85a2468b5e2d7fe4cc26fffef8fade0f0564c0ae23691a8e5b1d6914fd454ac
|
7
|
+
data.tar.gz: 13104718cd9f1973dcc78225bbe88ad62e1d89bfe67c40b256b9558a26c32a44404ee8de2063770c07a73fac0fac4387f11653faf011479e1dfe33ef0fd0dc4b
|
data/README.md
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
Catcher
|
2
2
|
====
|
3
3
|
|
4
|
-
Everytime you create a thread in ruby, you need to add some exception handling to know if something goes wrong (and what exactly went wrong).
|
4
|
+
Everytime you create a thread in ruby, you need to add some exception handling to know if something goes wrong (and what exactly went wrong). Same when you do background processing, unless you are already using some bigger framework for this. This gem helps you with that. No fireworks, just makes you write fewer lines to catch and log an exception.
|
5
5
|
|
6
|
-
|
6
|
+
First, somewhere in initialization you decide where to log:
|
7
7
|
|
8
8
|
Catcher.setup_logger "shit_happens.log"
|
9
9
|
|
10
|
-
Arguments are the same as for Logger.new.
|
10
|
+
Arguments are the same as for Logger.new. If you don't setup logger it defaults to STDOUT.
|
11
|
+
|
12
|
+
Then in your classes:
|
11
13
|
|
12
14
|
class Foo
|
13
15
|
include Catcher::Logger
|
14
16
|
|
15
17
|
def self.bar
|
16
|
-
log.info "gangnam style"
|
18
|
+
log.info "gangnam style" # wow, this gem is old
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
It could be
|
22
|
+
It could also be an instance method. It will produce something like this:
|
21
23
|
|
22
24
|
I, [2012-10-30 10:56:45 #20295] INFO -- : Foo : gangnam style
|
23
25
|
|
@@ -36,15 +38,15 @@ Exception gets catched and logged like this:
|
|
36
38
|
(irb):2:in `irb_binding'
|
37
39
|
(.. full backtrace here ..)
|
38
40
|
|
39
|
-
And finally
|
41
|
+
And finally, for threads, just use:
|
40
42
|
|
41
43
|
Catcher.thread "doing science" do
|
42
|
-
# your stuff
|
44
|
+
# your stuff in a thread
|
43
45
|
end
|
44
46
|
|
45
47
|
Which is equal to Thread.new with Catcher.block inside.
|
46
48
|
|
47
|
-
Description strings in Catcher.block and Catcher.thread are optional, but very much recommended. Comments and suggestions are
|
49
|
+
Description strings in Catcher.block and Catcher.thread are optional, but very much recommended. Comments and suggestions are welome.
|
48
50
|
|
49
51
|
Happy threading.
|
50
52
|
|
@@ -58,7 +60,7 @@ In your Gemfile:
|
|
58
60
|
Author
|
59
61
|
-------
|
60
62
|
|
61
|
-
Kacper Cieśla
|
63
|
+
Kacper Cieśla (comboy)
|
62
64
|
|
63
65
|
License
|
64
66
|
-------
|
data/lib/catcher.rb
CHANGED
@@ -20,6 +20,16 @@ module Catcher
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def self.thread_loop(progname = nil)
|
24
|
+
Thread.new do
|
25
|
+
loop do
|
26
|
+
block progname do
|
27
|
+
yield
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
23
33
|
def self.log_exception(e, progname)
|
24
34
|
text = progname ? "Exception raised by '#{progname}'\n\t" : ""
|
25
35
|
if e.kind_of? Exception
|
data/lib/catcher/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: catcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Kacper Cieśla
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Keep readable logs for your multithreaded ruby scripts
|
15
14
|
email:
|
@@ -18,41 +17,40 @@ executables: []
|
|
18
17
|
extensions: []
|
19
18
|
extra_rdoc_files: []
|
20
19
|
files:
|
20
|
+
- MIT-LICENSE
|
21
|
+
- README.md
|
22
|
+
- Rakefile
|
21
23
|
- lib/catcher.rb
|
22
|
-
- lib/catcher/prefixed_logger.rb
|
23
24
|
- lib/catcher/logger.rb
|
25
|
+
- lib/catcher/prefixed_logger.rb
|
24
26
|
- lib/catcher/version.rb
|
25
|
-
- MIT-LICENSE
|
26
|
-
- Rakefile
|
27
|
-
- README.md
|
28
|
-
- test/test_helper.rb
|
29
|
-
- test/catcher_test.rb
|
30
27
|
- test/catcher/logger_test.rb
|
28
|
+
- test/catcher_test.rb
|
29
|
+
- test/test_helper.rb
|
31
30
|
homepage: https://github.com/comboy/catcher
|
32
31
|
licenses: []
|
32
|
+
metadata: {}
|
33
33
|
post_install_message:
|
34
34
|
rdoc_options: []
|
35
35
|
require_paths:
|
36
36
|
- lib
|
37
37
|
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
38
|
requirements:
|
40
|
-
- -
|
39
|
+
- - ">="
|
41
40
|
- !ruby/object:Gem::Version
|
42
41
|
version: '0'
|
43
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
43
|
requirements:
|
46
|
-
- -
|
44
|
+
- - ">="
|
47
45
|
- !ruby/object:Gem::Version
|
48
46
|
version: '0'
|
49
47
|
requirements: []
|
50
48
|
rubyforge_project:
|
51
|
-
rubygems_version:
|
49
|
+
rubygems_version: 2.2.2
|
52
50
|
signing_key:
|
53
|
-
specification_version:
|
51
|
+
specification_version: 4
|
54
52
|
summary: Keep readable logs for your multithreaded ruby scripts
|
55
53
|
test_files:
|
56
54
|
- test/test_helper.rb
|
57
|
-
- test/catcher_test.rb
|
58
55
|
- test/catcher/logger_test.rb
|
56
|
+
- test/catcher_test.rb
|