Exceptional_Log 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Exceptional_Log.gemspec +34 -0
- data/Gemfile +6 -0
- data/README.md +48 -0
- data/Rakefile +3 -0
- data/lib/Exceptional_Log.rb +54 -0
- data/lib/Exceptional_Log/version.rb +1 -0
- data/spec/Exceptional_Log.rb +61 -0
- data/spec/bin.rb +13 -0
- data/spec/file/thin_A.log +16 -0
- data/spec/file/thin_B.log +16 -0
- data/spec/lib/main.rb +46 -0
- metadata +154 -0
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
require "Exceptional_Log/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "Exceptional_Log"
|
8
|
+
s.version = Exceptional_Log_Version
|
9
|
+
s.authors = ["da99"]
|
10
|
+
s.email = ["i-hate-spam-45671204@mailinator.com"]
|
11
|
+
s.homepage = "https://github.com/da99/Exceptional_Log"
|
12
|
+
s.summary = %q{Turn a file into an Exception-like object.}
|
13
|
+
s.description = %q{
|
14
|
+
|
15
|
+
Turn your log files into exceptions.
|
16
|
+
The contents are used as a backtrace.
|
17
|
+
|
18
|
+
}
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
|
25
|
+
s.add_development_dependency 'bacon'
|
26
|
+
s.add_development_dependency 'rake'
|
27
|
+
s.add_development_dependency 'Bacon_Colored'
|
28
|
+
s.add_development_dependency 'pry'
|
29
|
+
|
30
|
+
# Specify any dependencies here; for example:
|
31
|
+
# s.add_runtime_dependency 'rest-client'
|
32
|
+
s.add_runtime_dependency 'Split_Lines'
|
33
|
+
s.add_runtime_dependency 'Classy_Name'
|
34
|
+
end
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
Exceptional\_Log
|
3
|
+
================
|
4
|
+
|
5
|
+
A Ruby gem to turn your log files into exceptions.
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
gem install Exceptional_Log
|
11
|
+
|
12
|
+
Usage
|
13
|
+
------
|
14
|
+
|
15
|
+
require "Exceptional_Log"
|
16
|
+
|
17
|
+
e = Exceptional_Log("/my_apps/logs/thin_a.log")
|
18
|
+
|
19
|
+
e.class # --> Thin_A
|
20
|
+
e.message # --> '/my_apps/logs/thin_a.log'
|
21
|
+
e.backtrace # --> Array
|
22
|
+
e.exception # --> self
|
23
|
+
e.created_at # --> File.stat(file).atime
|
24
|
+
e.to_hash # --> Hash[ :exception => ..., :message => ..., :created_at => ..., :backtrace => ... ]
|
25
|
+
|
26
|
+
Each exception is a subclass of `Exceptional_Log` and is named based on the basename of
|
27
|
+
the file path.
|
28
|
+
|
29
|
+
Nginx/HTTP Error Logs
|
30
|
+
---------------------
|
31
|
+
|
32
|
+
For NGINX error logs (not access logs), try looking at
|
33
|
+
[the Http\_Error\_Log](https://github.com/da99/Http_Error_Log).
|
34
|
+
|
35
|
+
Run Tests
|
36
|
+
---------
|
37
|
+
|
38
|
+
git clone git@github.com:da99/Exceptional_Log.git
|
39
|
+
cd Exceptional_Log
|
40
|
+
bundle update
|
41
|
+
bundle exec bacon spec/lib/main.rb
|
42
|
+
|
43
|
+
"I hate writing."
|
44
|
+
-----------------------------
|
45
|
+
|
46
|
+
If you know of existing software that makes the above redundant,
|
47
|
+
please tell me. The last thing I want to do is maintain code.
|
48
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'Exceptional_Log/version'
|
2
|
+
require "Classy_Name"
|
3
|
+
|
4
|
+
class Exceptional_Log < RuntimeError
|
5
|
+
|
6
|
+
module Class_Methods
|
7
|
+
|
8
|
+
def convert file
|
9
|
+
f = file
|
10
|
+
full_path = File.expand_path(f)
|
11
|
+
msg = full_path
|
12
|
+
|
13
|
+
e_name = Classy_Name(File.basename(f).sub( /\.log\z/i, '' ))
|
14
|
+
|
15
|
+
k = begin
|
16
|
+
unless Object.const_defined?(e_name)
|
17
|
+
c = Class.new(Exceptional_Log)
|
18
|
+
Object.const_set e_name, c
|
19
|
+
end
|
20
|
+
|
21
|
+
Object.const_get e_name
|
22
|
+
end
|
23
|
+
|
24
|
+
e = k.new(msg)
|
25
|
+
e.set_backtrace Split_Lines(File.read full_path )
|
26
|
+
e.created_at = File.stat(full_path).atime
|
27
|
+
|
28
|
+
e
|
29
|
+
end
|
30
|
+
|
31
|
+
end # === Class_Methods
|
32
|
+
|
33
|
+
module Base
|
34
|
+
|
35
|
+
attr_accessor :created_at
|
36
|
+
|
37
|
+
def [] name
|
38
|
+
send name
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_hash
|
42
|
+
keys = %w{ exception message backtrace created_at }
|
43
|
+
keys.inject(Hash[]) { |memo, k|
|
44
|
+
memo[k.to_sym] = send(k)
|
45
|
+
memo
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
end # === Base
|
50
|
+
|
51
|
+
extend Class_Methods
|
52
|
+
include Base
|
53
|
+
|
54
|
+
end # === Exceptional_Log
|
@@ -0,0 +1 @@
|
|
1
|
+
Exceptional_Log_Version = "0.1.0"
|
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
describe "Exceptional_Log.convert file_path" do
|
3
|
+
|
4
|
+
before {
|
5
|
+
@files = Dir.glob("./spec/file/thin*.log")
|
6
|
+
@e = @files.map { |f|
|
7
|
+
Exceptional_Log.convert(f)
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
it "returns an Enumerable" do
|
12
|
+
@e.should.respond_to :each_index
|
13
|
+
end
|
14
|
+
|
15
|
+
it "turns each log into a Exceptional_Log" do
|
16
|
+
@e.each { |e| e.should.is_a Exceptional_Log }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets exception class to file basename: thin_A.log -> Thin_A" do
|
20
|
+
@files.each_index { |i|
|
21
|
+
@e[i].class.name
|
22
|
+
.should == File.basename(@files[i]).sub('.log', '').split("_").map(&:capitalize).join('_')
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets key :message to file path" do
|
27
|
+
File.file?( @e.first.message )
|
28
|
+
.should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sets key :backtrace as Array of lines from file" do
|
32
|
+
@e.last[:backtrace]
|
33
|
+
.should == Split_Lines( File.read(@files.last) )
|
34
|
+
end
|
35
|
+
|
36
|
+
it "sets key :created_at to :atime of file" do
|
37
|
+
@e.last[:created_at]
|
38
|
+
.should == File.stat(@files.last).atime
|
39
|
+
end
|
40
|
+
|
41
|
+
end # === Exceptional_Log ruby_glob
|
42
|
+
|
43
|
+
|
44
|
+
describe "Exceptional#to_hash" do
|
45
|
+
|
46
|
+
before {
|
47
|
+
@e = Exceptional_Log.convert(Dir.glob('spec/file/thin*').first)
|
48
|
+
@h = @e.to_hash
|
49
|
+
}
|
50
|
+
|
51
|
+
%w{ exception message backtrace created_at }.each { |k|
|
52
|
+
|
53
|
+
it "sets :#{k}" do
|
54
|
+
@h[:"#{k}"].should == @e.send(k)
|
55
|
+
end
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
end # === Exceptional#to_hash
|
61
|
+
|
data/spec/bin.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
bins = Dir.glob("bin/*")
|
3
|
+
|
4
|
+
unless bins.empty?
|
5
|
+
describe "permissions of bin/" do
|
6
|
+
bins.each { |file|
|
7
|
+
it "should chmod 755 for: #{file}" do
|
8
|
+
`stat -c %a #{file}`.strip
|
9
|
+
.should.be == "755"
|
10
|
+
end
|
11
|
+
}
|
12
|
+
end # === permissions of bin/
|
13
|
+
end # === unless bins.empty?
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/home/da01/MyLife/apps/GEMS/Exceptional_Log/spec/file/config.ru:1:in `block in <main>': uninitialized constant A (NameError)
|
2
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
|
3
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
|
4
|
+
from /home/da01/MyLife/apps/GEMS/Exceptional_Log/spec/file/config.ru:1:in `new'
|
5
|
+
from /home/da01/MyLife/apps/GEMS/Exceptional_Log/spec/file/config.ru:1:in `<main>'
|
6
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/rack/adapter/loader.rb:36:in `eval'
|
7
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/rack/adapter/loader.rb:36:in `load'
|
8
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/rack/adapter/loader.rb:45:in `for'
|
9
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/controllers/controller.rb:169:in `load_adapter'
|
10
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/controllers/controller.rb:73:in `start'
|
11
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/runner.rb:185:in `run_command'
|
12
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/runner.rb:151:in `run!'
|
13
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/bin/thin:6:in `<top (required)>'
|
14
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/bin/thin:23:in `load'
|
15
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/bin/thin:23:in `<main>'
|
16
|
+
>> Using rack adapter
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/home/da01/MyLife/apps/GEMS/Exceptional_Log/spec/file/config.ru:1:in `block in <main>': uninitialized constant B (NameError)
|
2
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
|
3
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
|
4
|
+
from /home/da01/MyLife/apps/GEMS/Exceptional_Log/spec/file/config.ru:1:in `new'
|
5
|
+
from /home/da01/MyLife/apps/GEMS/Exceptional_Log/spec/file/config.ru:1:in `<main>'
|
6
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/rack/adapter/loader.rb:36:in `eval'
|
7
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/rack/adapter/loader.rb:36:in `load'
|
8
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/rack/adapter/loader.rb:45:in `for'
|
9
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/controllers/controller.rb:169:in `load_adapter'
|
10
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/controllers/controller.rb:73:in `start'
|
11
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/runner.rb:185:in `run_command'
|
12
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/lib/thin/runner.rb:151:in `run!'
|
13
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/thin-1.3.1/bin/thin:6:in `<top (required)>'
|
14
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/bin/thin:23:in `load'
|
15
|
+
from /home/da01/.rbenv/versions/1.9.3-p194/bin/thin:23:in `<main>'
|
16
|
+
>> Using rack adapter
|
data/spec/lib/main.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.print e.message, "\n"
|
8
|
+
$stderr.print "Run `bundle install` to install missing gems\n"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'bacon'
|
12
|
+
|
13
|
+
Gem_Dir = File.expand_path( File.join(File.dirname(__FILE__) + '/../..') )
|
14
|
+
$LOAD_PATH.unshift Gem_Dir
|
15
|
+
$LOAD_PATH.unshift( Gem_Dir + "/lib" )
|
16
|
+
|
17
|
+
Bacon.summary_on_exit
|
18
|
+
|
19
|
+
require 'Exceptional_Log'
|
20
|
+
require 'Bacon_Colored'
|
21
|
+
require 'pry'
|
22
|
+
|
23
|
+
require 'Split_Lines'
|
24
|
+
|
25
|
+
|
26
|
+
# ======== Custom code.
|
27
|
+
|
28
|
+
# Nothing yet.
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
# ======== Include the tests.
|
34
|
+
target_files = ARGV[1, ARGV.size - 1].select { |a| File.file?(a) }
|
35
|
+
|
36
|
+
if target_files.empty?
|
37
|
+
|
38
|
+
# include all files
|
39
|
+
Dir.glob('./spec/*.rb').each { |file|
|
40
|
+
require file.sub('.rb', '') if File.file?(file)
|
41
|
+
}
|
42
|
+
|
43
|
+
else
|
44
|
+
# Do nothing. Bacon grabs the file.
|
45
|
+
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Exceptional_Log
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- da99
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bacon
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: Bacon_Colored
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: Split_Lines
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: Classy_Name
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: ! "\n\n Turn your log files into exceptions.\n The contents are
|
111
|
+
used as a backtrace.\n\n "
|
112
|
+
email:
|
113
|
+
- i-hate-spam-45671204@mailinator.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- Exceptional_Log.gemspec
|
120
|
+
- Gemfile
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- lib/Exceptional_Log.rb
|
124
|
+
- lib/Exceptional_Log/version.rb
|
125
|
+
- spec/Exceptional_Log.rb
|
126
|
+
- spec/bin.rb
|
127
|
+
- spec/file/thin_A.log
|
128
|
+
- spec/file/thin_B.log
|
129
|
+
- spec/lib/main.rb
|
130
|
+
homepage: https://github.com/da99/Exceptional_Log
|
131
|
+
licenses: []
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 1.8.23
|
151
|
+
signing_key:
|
152
|
+
specification_version: 3
|
153
|
+
summary: Turn a file into an Exception-like object.
|
154
|
+
test_files: []
|