jlog-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
File without changes
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@jlog-rails
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jlog-rails.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ jlog-rails
2
+ ==========
3
+
4
+ JLog - Rails integration with server side logger for JLog.js
5
+
6
+ Usage:
7
+ ------
8
+
9
+ In the Gemfile:
10
+
11
+ gem 'jlog-rails'
12
+
13
+ then:
14
+
15
+ rails g jlog:install
16
+
17
+ On the client-side:
18
+
19
+ var logger = new JLog();
20
+ logger.addAppender(new JLog.AjaxAppender('/jlog/append'));
21
+ logger.warn('warning to be recorded in the server-side log');
22
+
23
+ Changelog:
24
+ ----------
25
+
26
+ * 0.0.1
27
+ * Added InstallGenerator
28
+ * Renamed JLog to Jlog
29
+ * Moved to AjaxController ActionController::Metal
30
+ * Added support for server-side logging of client events with Rails.logger
31
+ * Added AjaxAppender
32
+ * Initial port of jlog.js
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require 'bundler'
2
+
3
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,24 @@
1
+ module Jlog
2
+
3
+ class AjaxController < ActionController::Metal
4
+ include ActionController::Rendering
5
+
6
+ def append
7
+ message = params[:message]
8
+ level_pattern = /([A-Z]*) - /
9
+ level = message.match(level_pattern)[1]
10
+ message = 'Client Log: ' << message
11
+
12
+ if ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'].include? level
13
+ Rails.logger.send(level.downcase.to_sym, message)
14
+ else
15
+ Rails.logger.warn('*** Attempt to log with a nonexistent level ***')
16
+ Rails.logger.warn(message)
17
+ end
18
+
19
+ render text: 'ok', status: :ok
20
+ end
21
+
22
+ end
23
+
24
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Jlog::Engine.routes.draw do
2
+
3
+ post 'append' => 'ajax#append'
4
+
5
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("lib/jlog/version")
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'jlog-rails'
6
+ s.version = Jlog::VERSION
7
+ s.date = '2012-08-31'
8
+ s.summary = "Jlog for Rails"
9
+ s.description = "A lightweight JavaScript logger (for Rails)"
10
+ s.authors = ["Alexey Golubev"]
11
+ s.email = 'oholubyev@heliostech.hk'
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.homepage = 'http://rubygems.org/gems/jlog-rails'
15
+
16
+ s.rubyforge_project = "jlog-rails"
17
+
18
+ s.add_dependency "jquery-rails"
19
+ end
@@ -0,0 +1,14 @@
1
+ module Jlog
2
+ class InstallGenerator < Rails::Generators::Base
3
+
4
+ desc "Install Jlog engine"
5
+
6
+ def mount_engine
7
+ puts "Mounting Jlog engine at /jlog in config/routes.rb"
8
+ insert_into_file("config/routes.rb", :after => /routes\.draw\sdo\n/) do
9
+ %Q{\n mount Jlog::Engine, at: '/jlog'\n}
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Jlog
2
+ class Engine < Rails::Engine
3
+ isolate_namespace Jlog
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Jlog
2
+ VERSION = '0.0.1'
3
+ end
data/lib/jlog-rails.rb ADDED
@@ -0,0 +1 @@
1
+ require "jlog/engine"
data/script/rails ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/test-engine/engine', __FILE__)
6
+
7
+ require 'rails/all'
8
+ require 'rails/engine/commands'
@@ -0,0 +1,195 @@
1
+ /**
2
+ *
3
+ * @author Marcus R Breese mailto:mbreese@users.sourceforge.net
4
+ * @license Apache License 2.0
5
+ * @version 0.31
6
+ *<pre>
7
+ **************************************************************
8
+ *
9
+ * Copyright 2005 Fourspaces Consulting, LLC
10
+ *
11
+ * Licensed under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License.
13
+ * You may obtain a copy of the License at
14
+ *
15
+ * http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License
22
+ *
23
+ **************************************************************
24
+ * </pre>
25
+ */
26
+
27
+ function JLog(name) {
28
+ var _currentLevel = JLog.ALL,
29
+ _appenders = [new JLog.ConsoleAppender],
30
+ _name = null,
31
+ _enabled = true;
32
+
33
+ this.setName = function(name) {
34
+ _name = name || null;
35
+ };
36
+
37
+ this.addAppender = function(appender) {
38
+ if (appender) {
39
+ _appenders.push(appender);
40
+ }
41
+ };
42
+
43
+ this.removeAppender = function(name) {
44
+ for (var i in _appenders) {
45
+ if (_appenders[i].name === name) {
46
+ _appenders.splice(i, 1);
47
+ }
48
+ }
49
+ return null;
50
+ };
51
+
52
+ this.turnOn = function() {
53
+ _enabled = true;
54
+ };
55
+
56
+ this.turnOff = function() {
57
+ _enabled = false;
58
+ };
59
+
60
+ this.isOn = function() {
61
+ return _enabled;
62
+ };
63
+
64
+ // Sets the current threshold log level for this Log instance. Only events that have a priority of this level or greater are logged.
65
+ this.setLevel = function(level) {
66
+ if (typeof level === 'number') {
67
+ if (level >= JLog.ALL && level <= JLog.NONE) {
68
+ _currentLevel = level;
69
+ } else {
70
+ _currentLevel = JLog.NONE;
71
+ }
72
+ } else if (level) {
73
+ switch(level) {
74
+ case 'all': _currentLevel = JLog.ALL; break;
75
+ case 'debug': _currentLevel = JLog.DEBUG; break;
76
+ case 'info': _currentLevel = JLog.INFO; break;
77
+ case 'error': _currentLevel = JLog.ERROR; break;
78
+ case 'fatal': _currentLevel = JLog.FATAL; break;
79
+ case 'warn': _currentLevel = JLog.WARN; break;
80
+ case 'none': // fall through to default
81
+ default: _currentLevel = JLog.NONE;
82
+ }
83
+ } else {
84
+ _currentLevel = JLog.NONE;
85
+ }
86
+ };
87
+
88
+ this.getName = function() {
89
+ return _name;
90
+ };
91
+
92
+ this.getAppender = function(name) {
93
+ for (var i in _appenders) {
94
+ if (_appenders[i].name === name) {
95
+ return _appenders[i];
96
+ }
97
+ }
98
+ return null;
99
+ };
100
+
101
+ this.getAppenders = function() {
102
+ return _appenders;
103
+ };
104
+
105
+ this.getLevel = function() {
106
+ return _currentLevel;
107
+ };
108
+
109
+ if (name) {
110
+ this.setName(name);
111
+ }
112
+ };
113
+
114
+ JLog.ALL = 0;
115
+ JLog.DEBUG = 1;
116
+ JLog.INFO = 2;
117
+ JLog.WARN = 3;
118
+ JLog.ERROR = 4;
119
+ JLog.FATAL = 5;
120
+ JLog.NONE = 6;
121
+
122
+ JLog.prototype.debug = function() {
123
+ if (this.getLevel() <= JLog.DEBUG) {
124
+ this._log("DEBUG", arguments);
125
+ }
126
+ };
127
+
128
+ JLog.prototype.info = function() {
129
+ if (this.getLevel() <= JLog.INFO) {
130
+ this._log("INFO", arguments);
131
+ }
132
+ };
133
+
134
+ JLog.prototype.warn = function() {
135
+ if (this.getLevel() <= JLog.WARN) {
136
+ this._log("WARN", arguments);
137
+ }
138
+ };
139
+
140
+ JLog.prototype.error = function() {
141
+ if (this.getLevel() <= JLog.ERROR) {
142
+ this._log("ERROR", arguments);
143
+ }
144
+ };
145
+
146
+ JLog.prototype.fatal = function() {
147
+ if (this.getLevel() <= JLog.FATAL) {
148
+ this._log("FATAL", arguments);
149
+ }
150
+ };
151
+
152
+ JLog.prototype._log = function() {
153
+ if (this.isOn()) {
154
+ var level = arguments[0],
155
+ args = Array.prototype.slice.call(arguments[1]),
156
+ namePrefix = this.getName() ? this.getName() + ': ' : '',
157
+ msgString = level + ' - ' + namePrefix,
158
+ appenders = this.getAppenders();
159
+
160
+ for (var i in args) {
161
+ if (typeof args[i] === 'object') {
162
+ args[i] = JSON.stringify(args[i]);
163
+ }
164
+ }
165
+
166
+ msgString += args.join(', ');
167
+ for (var i in appenders) {
168
+ appenders[i].log(msgString);
169
+ }
170
+ }
171
+ };
172
+
173
+ JLog.ConsoleAppender = function() {
174
+ return {
175
+ name: 'ConsoleAppender',
176
+
177
+ log: function(msg) {
178
+ if (window.console) {
179
+ window.console.log(msg);
180
+ }
181
+ }
182
+ }
183
+ };
184
+
185
+ JLog.AjaxAppender = function(url) {
186
+ var _url = url;
187
+
188
+ return {
189
+ name: 'AjaxAppender',
190
+
191
+ log: function(msg) {
192
+ $.post(_url, {message: msg});
193
+ }
194
+ }
195
+ };
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jlog-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexey Golubev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jquery-rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
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
+ description: A lightweight JavaScript logger (for Rails)
31
+ email: oholubyev@heliostech.hk
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - .rvmrc
38
+ - Gemfile
39
+ - README.md
40
+ - Rakefile
41
+ - app/controllers/jlog/ajax_controller.rb
42
+ - config/routes.rb
43
+ - jlog-rails.gemspec
44
+ - lib/generators/jlog/install_generator.rb
45
+ - lib/jlog-rails.rb
46
+ - lib/jlog/engine.rb
47
+ - lib/jlog/version.rb
48
+ - script/rails
49
+ - vendor/assets/javascripts/jlog.js
50
+ homepage: http://rubygems.org/gems/jlog-rails
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project: jlog-rails
70
+ rubygems_version: 1.8.22
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Jlog for Rails
74
+ test_files: []