rails-client-logger 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +50 -4
- data/app/controllers/rails_client_logger/rails_client_loggers_controller.rb +4 -0
- data/lib/generators/rails_client_logger/rails_client_logger_generator.rb +22 -7
- data/lib/rails-client-logger/version.rb +1 -1
- data/test/dummy/config/application.rb +2 -0
- data/test/dummy/config/environments/test.rb +4 -4
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +10 -0
- data/test/functional/js_logger/js_loggers_controller_test.rb +1 -1
- data/vendor/assets/javascripts/rails_client_logger.js.coffee +15 -0
- metadata +35 -13
- data/vendor/assets/javascripts/rails_client_logger.js +0 -34
data/README.md
CHANGED
@@ -4,18 +4,28 @@ Rails engine to log from Client side (Browser) javascript to server log file. To
|
|
4
4
|
|
5
5
|
There are 5 levels of logging: debug, info, warn, error and fatal.
|
6
6
|
|
7
|
+
Supports Rails 4 (permitted parameters) as well as a CoffeeScript implementation of the client-side code.
|
8
|
+
|
9
|
+
For Rails 3.x use gem version `0.0.2`.
|
10
|
+
|
7
11
|
## Installation
|
8
12
|
|
9
13
|
Add this line to your application's Gemfile:
|
10
14
|
|
15
|
+
### For Rails 4.x
|
11
16
|
```ruby
|
12
17
|
gem 'rails-client-logger'
|
13
18
|
```
|
14
|
-
|
19
|
+
|
20
|
+
### For Rails 3.x
|
21
|
+
```ruby
|
22
|
+
gem 'rails-client-logger', '0.0.2'
|
23
|
+
```
|
24
|
+
|
15
25
|
And then execute:
|
16
26
|
|
17
27
|
```bash
|
18
|
-
$ bundle
|
28
|
+
$ bundle install
|
19
29
|
```
|
20
30
|
|
21
31
|
Then simply execute following generator command. It inserts the required routes and javascript files and you're ready to rock!
|
@@ -32,7 +42,7 @@ $ rails g rails_client_logger
|
|
32
42
|
jsLogger.info("simple info message");
|
33
43
|
jsLogger.warn("a warning");
|
34
44
|
```
|
35
|
-
|
45
|
+
|
36
46
|
### Log Error
|
37
47
|
|
38
48
|
```ruby
|
@@ -43,7 +53,40 @@ catch (e) {
|
|
43
53
|
jsLogger.fatal(e);
|
44
54
|
}
|
45
55
|
```
|
46
|
-
|
56
|
+
|
57
|
+
Log all unhandled javascript errors:
|
58
|
+
|
59
|
+
```javascript
|
60
|
+
window.onerror = function (message, url, line_number) {
|
61
|
+
jsLogger.fatal("Uncaught errror in: " + url + ":" + line_number + "\nDetails: " + message);
|
62
|
+
};
|
63
|
+
```
|
64
|
+
|
65
|
+
### View Logs
|
66
|
+
|
67
|
+
The logged messages will appear in the normal rails log (i.e. development.log or staging.log or production.log).
|
68
|
+
|
69
|
+
## Authorization
|
70
|
+
|
71
|
+
The gem uses a controller to send messages to the server, in some cases you may need to authorize the controller actions for it to work correctly (otherwise you will get an authorization error). Below is a how-to guide for CanCan, but the same principles can be applied to other authorization gems.
|
72
|
+
|
73
|
+
### CanCan
|
74
|
+
|
75
|
+
1. Create a new controller `logger_controller.rb` that inherits from `RailsClientLoggersController` like this:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
class LoggerController < RailsClientLogger::RailsClientLoggersController
|
79
|
+
skip_authorization_check
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
2. Add a new route in `routes.rb`
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
match 'logger/rails_client_logger/log' => 'logger#log'
|
87
|
+
mount RailsClientLogger::Engine, :at => "logger"
|
88
|
+
```
|
89
|
+
|
47
90
|
## Contributing
|
48
91
|
|
49
92
|
1. Fork it
|
@@ -58,6 +101,9 @@ catch (e) {
|
|
58
101
|
|
59
102
|
[girishso](https://github.com/girishso) - for the implementation
|
60
103
|
|
104
|
+
[elthariel](https://github.com/elthariel) - for Rails 4 support and CoffeeScript
|
105
|
+
implementation
|
106
|
+
|
61
107
|
## License
|
62
108
|
MIT License
|
63
109
|
|
@@ -1,19 +1,34 @@
|
|
1
1
|
class RailsClientLoggerGenerator < Rails::Generators::Base
|
2
2
|
source_root File.expand_path('../templates', __FILE__)
|
3
|
-
|
3
|
+
|
4
4
|
desc "inserts required routes and requires the javascript files"
|
5
5
|
def generate
|
6
6
|
# add route
|
7
7
|
route(%Q{mount RailsClientLogger::Engine, :at => "logger"})
|
8
|
-
|
8
|
+
|
9
|
+
mode = :coffee
|
10
|
+
if File.exists? "app/assets/javascripts/application.js.coffee"
|
11
|
+
path = "app/assets/javascripts/application.js.coffee"
|
12
|
+
elsif File.exists? "app/assets/javascripts/application.coffee"
|
13
|
+
path = "app/assets/javascripts/application.coffee"
|
14
|
+
elsif File.exists? "app/assets/javascripts/application.js"
|
15
|
+
mode = :js
|
16
|
+
path = "app/assets/javascripts/application.js"
|
17
|
+
end
|
18
|
+
|
9
19
|
# add to application.js manifest
|
10
|
-
|
11
|
-
if
|
12
|
-
say_status("skipped", "insert into
|
20
|
+
original = File.binread(path)
|
21
|
+
if original.include?("require rails_client_logger")
|
22
|
+
say_status("skipped", "insert into #{path}", :yellow)
|
13
23
|
else
|
14
|
-
|
24
|
+
if mode == :coffee
|
25
|
+
insert_into_file path, :after => %r{#= require ['"]?jquery['"]?\s*$} do
|
26
|
+
"\n#= require rails_client_logger"
|
27
|
+
else
|
28
|
+
insert_into_file path, :after => %r{//= require ['"]?jquery['"]?\s*$} do
|
15
29
|
"\n//= require rails_client_logger"
|
16
|
-
|
30
|
+
end
|
31
|
+
end
|
17
32
|
end
|
18
33
|
end
|
19
34
|
end
|
@@ -11,9 +11,6 @@ Dummy::Application.configure do
|
|
11
11
|
config.serve_static_assets = true
|
12
12
|
config.static_cache_control = "public, max-age=3600"
|
13
13
|
|
14
|
-
# Log error messages when you accidentally call methods on nil
|
15
|
-
config.whiny_nils = true
|
16
|
-
|
17
14
|
# Show full error reports and disable caching
|
18
15
|
config.consider_all_requests_local = true
|
19
16
|
config.action_controller.perform_caching = false
|
@@ -30,8 +27,11 @@ Dummy::Application.configure do
|
|
30
27
|
config.action_mailer.delivery_method = :test
|
31
28
|
|
32
29
|
# Raise exception on mass assignment protection for Active Record models
|
33
|
-
config.active_record.mass_assignment_sanitizer = :strict
|
30
|
+
# config.active_record.mass_assignment_sanitizer = :strict
|
34
31
|
|
35
32
|
# Print deprecation notices to the stderr
|
36
33
|
config.active_support.deprecation = :stderr
|
34
|
+
|
35
|
+
# Rails 4 new stuff
|
36
|
+
config.eager_load = false
|
37
37
|
end
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
2
|
+
------------------------------------------------------
|
3
|
+
JsLogger::JsLoggersControllerTest: test_should_get_log
|
4
|
+
------------------------------------------------------
|
5
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
6
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
7
|
+
------------------------
|
8
|
+
JsLoggerTest: test_truth
|
9
|
+
------------------------
|
10
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
@@ -0,0 +1,15 @@
|
|
1
|
+
window.jsLogger =
|
2
|
+
invoke: (level, message) ->
|
3
|
+
jQuery.ajax {
|
4
|
+
type: 'post'
|
5
|
+
beforeSend: (xhr) ->
|
6
|
+
xhr.setRequestHeader('X-CSRF-Token', jQuery('meta[name="csrf-token"]').attr('content'))
|
7
|
+
data: {level: level, message: message}
|
8
|
+
complete: (request) ->
|
9
|
+
# Nothing yet
|
10
|
+
url: "/logger/rails_client_logger/log"
|
11
|
+
}
|
12
|
+
|
13
|
+
for level in ['debug', 'info', 'warn', 'error', 'fatal']
|
14
|
+
jsLogger[level] = (msg) ->
|
15
|
+
jsLogger.invoke(level, msg)
|
metadata
CHANGED
@@ -1,51 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-client-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Girish Sonawane
|
9
|
+
- Julien 'Lta' Ballet
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rails
|
17
|
+
type: :runtime
|
16
18
|
requirement: !ruby/object:Gem::Requirement
|
17
19
|
none: false
|
18
20
|
requirements:
|
19
21
|
- - ! '>='
|
20
22
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
23
|
+
version: '4.0'
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '4.0'
|
30
|
+
prerelease: false
|
30
31
|
- !ruby/object:Gem::Dependency
|
31
32
|
name: sqlite3
|
33
|
+
type: :development
|
32
34
|
requirement: !ruby/object:Gem::Requirement
|
33
35
|
none: false
|
34
36
|
requirements:
|
35
37
|
- - ! '>='
|
36
38
|
- !ruby/object:Gem::Version
|
37
39
|
version: '0'
|
38
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
39
46
|
prerelease: false
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: protected_attributes
|
49
|
+
type: :development
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
40
56
|
version_requirements: !ruby/object:Gem::Requirement
|
41
57
|
none: false
|
42
58
|
requirements:
|
43
59
|
- - ! '>='
|
44
60
|
- !ruby/object:Gem::Version
|
45
61
|
version: '0'
|
62
|
+
prerelease: false
|
46
63
|
description: Rails engine for logging from Browser Javascript to server
|
47
64
|
email:
|
48
65
|
- girish.sonawane@gmail.com
|
66
|
+
- elthariel@gmail.com
|
49
67
|
executables: []
|
50
68
|
extensions: []
|
51
69
|
extra_rdoc_files: []
|
@@ -59,7 +77,7 @@ files:
|
|
59
77
|
- lib/rails-client-logger/version.rb
|
60
78
|
- lib/rails-client-logger.rb
|
61
79
|
- lib/tasks/js-logger_tasks.rake
|
62
|
-
- vendor/assets/javascripts/rails_client_logger.js
|
80
|
+
- vendor/assets/javascripts/rails_client_logger.js.coffee
|
63
81
|
- MIT-LICENSE
|
64
82
|
- Rakefile
|
65
83
|
- README.md
|
@@ -84,6 +102,8 @@ files:
|
|
84
102
|
- test/dummy/config/locales/en.yml
|
85
103
|
- test/dummy/config/routes.rb
|
86
104
|
- test/dummy/config.ru
|
105
|
+
- test/dummy/db/test.sqlite3
|
106
|
+
- test/dummy/log/test.log
|
87
107
|
- test/dummy/public/404.html
|
88
108
|
- test/dummy/public/422.html
|
89
109
|
- test/dummy/public/500.html
|
@@ -107,22 +127,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
127
|
requirements:
|
108
128
|
- - ! '>='
|
109
129
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
130
|
segments:
|
112
131
|
- 0
|
113
|
-
|
132
|
+
version: '0'
|
133
|
+
hash: 92147991256340174
|
114
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
135
|
none: false
|
116
136
|
requirements:
|
117
137
|
- - ! '>='
|
118
138
|
- !ruby/object:Gem::Version
|
119
|
-
version: '0'
|
120
139
|
segments:
|
121
140
|
- 0
|
122
|
-
|
141
|
+
version: '0'
|
142
|
+
hash: 92147991256340174
|
123
143
|
requirements: []
|
124
144
|
rubyforge_project:
|
125
|
-
rubygems_version: 1.8.
|
145
|
+
rubygems_version: 1.8.25
|
126
146
|
signing_key:
|
127
147
|
specification_version: 3
|
128
148
|
summary: Rails engine for logging from Browser Javascript to server
|
@@ -148,6 +168,8 @@ test_files:
|
|
148
168
|
- test/dummy/config/locales/en.yml
|
149
169
|
- test/dummy/config/routes.rb
|
150
170
|
- test/dummy/config.ru
|
171
|
+
- test/dummy/db/test.sqlite3
|
172
|
+
- test/dummy/log/test.log
|
151
173
|
- test/dummy/public/404.html
|
152
174
|
- test/dummy/public/422.html
|
153
175
|
- test/dummy/public/500.html
|
@@ -1,34 +0,0 @@
|
|
1
|
-
(function( jsLogger, $, undefined ) {
|
2
|
-
//Public Method
|
3
|
-
jsLogger.debug = function(message) {
|
4
|
-
invoke('debug', message);
|
5
|
-
};
|
6
|
-
|
7
|
-
jsLogger.info = function(message) {
|
8
|
-
invoke('info', message);
|
9
|
-
};
|
10
|
-
|
11
|
-
jsLogger.warn = function(message) {
|
12
|
-
invoke('warn', message);
|
13
|
-
};
|
14
|
-
|
15
|
-
jsLogger.error = function(message) {
|
16
|
-
invoke('error', message);
|
17
|
-
};
|
18
|
-
|
19
|
-
jsLogger.fatal = function(message) {
|
20
|
-
invoke('fatal', message);
|
21
|
-
};
|
22
|
-
|
23
|
-
|
24
|
-
//Private Method
|
25
|
-
function invoke(level, message) {
|
26
|
-
$.ajax({
|
27
|
-
type: 'post',
|
28
|
-
beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))},
|
29
|
-
data: {level: level, message: message},
|
30
|
-
complete: function(request){},
|
31
|
-
url: "/logger/rails_client_logger/log"
|
32
|
-
})
|
33
|
-
}
|
34
|
-
}( window.jsLogger = window.jsLogger || {}, jQuery ));
|