exception_log 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +4 -0
- data/Rakefile +27 -0
- data/VERSION +1 -0
- data/lib/exception_log.rb +2 -0
- data/lib/exception_log/handler.rb +62 -0
- data/lib/exception_log/mailer.rb +14 -0
- data/lib/exception_log/middleware.rb +21 -0
- data/lib/exception_log/version.rb +3 -0
- data/lib/nodejs/server.js +49 -0
- metadata +57 -0
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'action_mailer'
|
4
|
+
require 'exception_log'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'bundler/setup'
|
8
|
+
rescue LoadError
|
9
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
10
|
+
end
|
11
|
+
|
12
|
+
task :build do
|
13
|
+
system "gem build exception_log.gemspec"
|
14
|
+
end
|
15
|
+
|
16
|
+
task :install => :build do
|
17
|
+
system "gem install exception_log-#{ExceptionLog::VERSION}.gem"
|
18
|
+
end
|
19
|
+
|
20
|
+
task :release => :build do
|
21
|
+
puts "Tagging #{ExceptionLog::VERSION}..."
|
22
|
+
system "git tag -a #{ExceptionLog::VERSION} -m 'Tagging #{ExceptionLog::VERSION}'"
|
23
|
+
puts "Pushing to Github..."
|
24
|
+
system "git push --tags"
|
25
|
+
puts "Pushing to rubygems.org..."
|
26
|
+
system "gem push exception_log-#{ExceptionLog::VERSION}.gem"
|
27
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#encoding:utf-8
|
2
|
+
require File.expand_path("../mailer.rb",__FILE__)
|
3
|
+
|
4
|
+
module ExceptionLog
|
5
|
+
class Handler
|
6
|
+
|
7
|
+
def initialize(env,exception,options={})
|
8
|
+
@exception = exception
|
9
|
+
@request = ActionDispatch::Request.new(env)
|
10
|
+
@controller = env['action_controller.instance']
|
11
|
+
@options = options
|
12
|
+
@body = generate_text
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate_text
|
16
|
+
org_str = if @controller.respond_to? :current_orgnization
|
17
|
+
org = @controller.send(:current_orgnization)
|
18
|
+
"orgnization: #{org.try(:id)} #{org.try(:name)}"
|
19
|
+
end
|
20
|
+
user_str = if @controller.respond_to? :current_user
|
21
|
+
user = @controller.send(:current_user)
|
22
|
+
"user: #{user.try(:id)} #{user.try(:name)}"
|
23
|
+
end
|
24
|
+
error =<<HERE
|
25
|
+
\n\n\n========================================= EXCEPTION ==============================================================
|
26
|
+
#{org_str}
|
27
|
+
#{user_str}
|
28
|
+
time: #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}
|
29
|
+
method: #{@request.method}
|
30
|
+
url: #{@request.url}
|
31
|
+
user-agent: #{@request.user_agent}
|
32
|
+
referer: #{@request.headers["Referer"]}
|
33
|
+
params: #{@controller.params}
|
34
|
+
exception: #{@exception.class}
|
35
|
+
message: #{@exception.message}
|
36
|
+
backtace: \n#{@exception.backtrace.join("\n")}
|
37
|
+
HERE
|
38
|
+
return error
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_log_path
|
42
|
+
"#{Rails.root}/log/exception.log"
|
43
|
+
end
|
44
|
+
|
45
|
+
def write_file
|
46
|
+
log_path = @options[:log_path] || default_log_path
|
47
|
+
File.open(log_path,"a+") do |f|
|
48
|
+
f.puts @body
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def send_mail
|
53
|
+
ExceptionLog::Mailer.exception_mail(@body,:from=>@options[:from],:to=>@options[:to]).deliver
|
54
|
+
end
|
55
|
+
|
56
|
+
def do
|
57
|
+
write_file
|
58
|
+
send_mail
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#encoding:utf-8
|
2
|
+
module ExceptionLog
|
3
|
+
class Mailer < ::ActionMailer::Base
|
4
|
+
|
5
|
+
def exception_mail(body,options = {})
|
6
|
+
from = options[:from]
|
7
|
+
to = options[:to]
|
8
|
+
subject = "NOTICE,your site raise a exception!"
|
9
|
+
body = body
|
10
|
+
mail(:from=>from, :to => to, :subject => subject, :body => body)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#encoding:utf-8
|
2
|
+
require File.expand_path("../handler",__FILE__)
|
3
|
+
|
4
|
+
module ExceptionLog
|
5
|
+
class Middleware
|
6
|
+
def initialize(app, options = {})
|
7
|
+
@app = app
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
@app.call(env)
|
13
|
+
rescue Exception => e
|
14
|
+
pid = fork {
|
15
|
+
ExceptionLog::Handler.new(env,e,@options).do
|
16
|
+
}
|
17
|
+
Process.detach(pid)
|
18
|
+
raise e
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
// node /data/projects/exception_log/lib/nodejs/server.js -host=192.168.10.107 -log=/data/projects/entos/log/exception.log
|
2
|
+
|
3
|
+
var app = require('http').createServer(handler)
|
4
|
+
, io = require('socket.io').listen(app)
|
5
|
+
// , fs = require('fs')
|
6
|
+
|
7
|
+
var args = process.argv.slice(2); //
|
8
|
+
var host = args[0].substr(6);
|
9
|
+
var log = args[1].substr(5)
|
10
|
+
|
11
|
+
console.log("listeing log:" + log);
|
12
|
+
|
13
|
+
app.listen(1337);
|
14
|
+
|
15
|
+
function handler (req, res) {
|
16
|
+
|
17
|
+
var data = '<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>' +
|
18
|
+
'<script src="http://'+ host +':1337/socket.io/socket.io.js"></script>' +
|
19
|
+
'<style type="text/css" media="screen">' +
|
20
|
+
'body {background:#000; color:#fff;}' +
|
21
|
+
'</style>' +
|
22
|
+
|
23
|
+
'<div style="width:100%">' +
|
24
|
+
'<pre id="tail"></pre>' +
|
25
|
+
'</div>' +
|
26
|
+
|
27
|
+
'<script type="text/javascript">' +
|
28
|
+
'var socket = io.connect("http://'+ host +':1337");' +
|
29
|
+
'socket.on("tail", function (data) {' +
|
30
|
+
'$("#tail").append(data.tail);' +
|
31
|
+
'}); ' +
|
32
|
+
'</script>';
|
33
|
+
|
34
|
+
res.writeHead(200);
|
35
|
+
res.end(data);
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
io.sockets.on('connection', function (socket) {
|
40
|
+
var spawn = require('child_process').spawn;
|
41
|
+
var tail = spawn("tail", ["-n10000", "-f" , log]);
|
42
|
+
|
43
|
+
tail.stdout.on("data", function (data) {
|
44
|
+
// console.log(data.toString('utf-8'));
|
45
|
+
socket.emit('tail', { tail : data.toString('utf-8') } )
|
46
|
+
});
|
47
|
+
});
|
48
|
+
|
49
|
+
console.log('Log Server running now at http://'+ host +':1337/ in your browser');
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exception_log
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- wxianfeng
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-08 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: rails exception send to email, and watch in web ui interface
|
15
|
+
email:
|
16
|
+
- wang.fl1429@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- README.md
|
22
|
+
- VERSION
|
23
|
+
- Rakefile
|
24
|
+
- lib/exception_log/middleware.rb
|
25
|
+
- lib/exception_log/mailer.rb
|
26
|
+
- lib/exception_log/version.rb
|
27
|
+
- lib/exception_log/handler.rb
|
28
|
+
- lib/nodejs/server.js
|
29
|
+
- lib/exception_log.rb
|
30
|
+
homepage: http://github.com/wxianfeng/exception_log
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
hash: -3635286804832592620
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.3.6
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.24
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: rails exception send to email, and watch in web ui interface
|
57
|
+
test_files: []
|