lena 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +48 -0
- data/Rakefile +29 -0
- data/app/assets/javascripts/lena.coffee +78 -0
- data/app/controllers/lena/lena_controller.rb +8 -0
- data/config/routes.rb +3 -0
- data/lib/lena.rb +4 -0
- data/lib/lena/engine.rb +20 -0
- data/lib/lena/rails/routing.rb +7 -0
- data/lib/lena/routing.rb +13 -0
- data/lib/lena/version.rb +3 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +14 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/views/application/index.html +3 -0
- data/spec/dummy/app/views/application/log.html +4 -0
- data/spec/dummy/app/views/application/throw.html +4 -0
- data/spec/dummy/app/views/application/throw_callstack.html +10 -0
- data/spec/dummy/app/views/layouts/application.html.erb +13 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +14 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +9 -0
- data/spec/dummy/config/environments/test.rb +12 -0
- data/spec/dummy/config/initializers/lena.rb +10 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/routes.rb +7 -0
- data/spec/dummy/log/development.log +170 -0
- data/spec/dummy/log/test.log +352 -0
- data/spec/dummy/spec/javascripts/support/jasmine.yml +20 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1c6fd1c437c9411ba952f11bacc0320f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/746c4b5e95c34b98c11d314938f4eaf1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/b7a52d401e731277ea560db378ef97c3 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/1c6fd1c437c9411ba952f11bacc0320f +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/b7a52d401e731277ea560db378ef97c3 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/features/lena_spec.rb +30 -0
- data/spec/spec_helper.rb +51 -0
- metadata +239 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af1c091763d076159eb0bf25c8a8dc5c324108fb
|
4
|
+
data.tar.gz: 61316f9e5b1c8acad448fc65753c7038202546c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7f6409860c8a4d0ea141264dd6a478e16d5dd3ef6ad26db77273658763fcb943a2ec53b16ccee02b4503a46210b2e987453f4c2983437c87d2c4f29404bfd18d
|
7
|
+
data.tar.gz: a562b29218b58b5f36ca29f88c636842bfa57643bcc537b1bc620f3250f84e429eea364533a1a2e87137a3fd77a4a6495d27f5d69fe563a9db2d4d93ba1aae05
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Whitney Young
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= Leña {<img src="https://secure.travis-ci.org/wbyoung/lena.png"/>}[http://travis-ci.org/wbyoung/lena] {<img src="https://codeclimate.com/github/wbyoung/lena.png"/>}[https://codeclimate.com/github/wbyoung/lena] {<img src="https://coveralls.io/repos/wbyoung/lena/badge.png"/>}[https://coveralls.io/r/wbyoung/lena]
|
2
|
+
|
3
|
+
Leña provides simple server-side JavaScript error logging for production Rails applications. This allows you to better track errors that occur in your front-end code.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Add the following to your +application.js+:
|
8
|
+
|
9
|
+
//= require lena
|
10
|
+
|
11
|
+
Add the following to your +routes.rb+:
|
12
|
+
|
13
|
+
mount Lena::Engine => "/lena"
|
14
|
+
|
15
|
+
Update your +application.html.erb+:
|
16
|
+
|
17
|
+
<%= javascript_include_tag "application", lena.configuration %>
|
18
|
+
|
19
|
+
If you use Turbolinks or provide other options for your javascript include, you can merge them: <tt>lena.configuration.merge("data-something" => true)</tt>.
|
20
|
+
|
21
|
+
== Usage Client Side
|
22
|
+
|
23
|
+
Leña will now track all exceptions that are thrown in your application. You can also use Leña to log individual errors without throwing an exception. In your JavaScript, simply:
|
24
|
+
|
25
|
+
lena.log('My Error Message')
|
26
|
+
|
27
|
+
== Usage Server Side
|
28
|
+
|
29
|
+
Leña will simply throw an exception, <tt>Lena::JavaScriptError</tt>, when it receives a log message. Why? Because you should be using {something}[https://github.com/smartinez87/exception_notification] to report server errors when they occur. Also that's basically what's happening on the client side, so why not throw an exception on the server?
|
30
|
+
|
31
|
+
If you need to configure what Leña does, you can add +config/initializers/lena.rb+:
|
32
|
+
|
33
|
+
Lena.setup do |config|
|
34
|
+
config.javascript_handler = Proc.new do |params|
|
35
|
+
# Custom handling of log message here
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
== Alternative Setup
|
41
|
+
|
42
|
+
An alternative to setting up Leña on your +application.js+ file is to import Leña separately. This may impact performance, but it will catch compiler errors in any scripts included after it:
|
43
|
+
|
44
|
+
<%= javascript_include_tag "lena", lena.configuration %>
|
45
|
+
|
46
|
+
== License
|
47
|
+
|
48
|
+
This project is distributed under the MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Lena'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each { |f| load f }
|
22
|
+
|
23
|
+
require 'rspec/core'
|
24
|
+
require 'rspec/core/rake_task'
|
25
|
+
|
26
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
27
|
+
RSpec::Core::RakeTask.new
|
28
|
+
|
29
|
+
task :default => :spec
|
@@ -0,0 +1,78 @@
|
|
1
|
+
throw new Error('Lena has already been loaded!') if window.lena != undefined
|
2
|
+
|
3
|
+
# Global settings for Leña read from the script element that loaded this.
|
4
|
+
Settings = do ->
|
5
|
+
elements = document.getElementsByTagName 'script'
|
6
|
+
read = (attribute) ->
|
7
|
+
attributes = (el.getAttribute(attribute) for el in elements)
|
8
|
+
attributes = (attribute for attribute in attributes when attribute)
|
9
|
+
attributes[0]
|
10
|
+
destination: read('data-lena-destination')
|
11
|
+
submitURL: read('data-lena-url')
|
12
|
+
|
13
|
+
# The handlers for each type of logging.
|
14
|
+
# These take an object with the following properties:
|
15
|
+
# message: The error message
|
16
|
+
# stacktrace: The stack trace that led to the error (could be null)
|
17
|
+
handlers =
|
18
|
+
remote: (data) ->
|
19
|
+
query = for key, value of data when value
|
20
|
+
"#{key}=#{encodeURIComponent(value)}"
|
21
|
+
xhr = new XMLHttpRequest()
|
22
|
+
xhr.open "post", Settings.submitURL, true
|
23
|
+
xhr.setRequestHeader 'Content-type', 'application/x-www-form-urlencoded'
|
24
|
+
xhr.send query.join('&')
|
25
|
+
|
26
|
+
local: (data) ->
|
27
|
+
message = data.message
|
28
|
+
message = "#{message}\n#{data.stacktrace}" if data.stacktrace
|
29
|
+
|
30
|
+
if console?.warn
|
31
|
+
console.warn(message)
|
32
|
+
else if console?.log
|
33
|
+
console.log(message)
|
34
|
+
else
|
35
|
+
alert(message)
|
36
|
+
|
37
|
+
# The main Leña handler. All user calls go through here. The final
|
38
|
+
# data is aggregated before it is dispatched to one of the handlers.
|
39
|
+
lena = (message, stacktrace, destinations=[]) ->
|
40
|
+
if stacktrace == undefined
|
41
|
+
try
|
42
|
+
throw new Error('')
|
43
|
+
catch e
|
44
|
+
stacktrace = e.stack
|
45
|
+
try
|
46
|
+
stacktrace = stacktrace.split("\n")[2..].join("\n")
|
47
|
+
try
|
48
|
+
stacktrace ||= 'unsupported'
|
49
|
+
|
50
|
+
data =
|
51
|
+
message: message
|
52
|
+
stacktrace: stacktrace
|
53
|
+
|
54
|
+
handlers[d](data) for d in destinations
|
55
|
+
|
56
|
+
# Log a message via Leña. This uses the configuration values to determine
|
57
|
+
# where the message should be sent (remote/local/both).
|
58
|
+
lena.log = (message, stacktrace) ->
|
59
|
+
destinations = []
|
60
|
+
switch Settings.destination
|
61
|
+
when 'local' then destinations = ['local']
|
62
|
+
when 'remote' then destinations = ['remote']
|
63
|
+
else destinations = ['local', 'remote']
|
64
|
+
lena(message, stacktrace, destinations)
|
65
|
+
|
66
|
+
# Log a message via Leña. Only logs remote (server).
|
67
|
+
lena.remote = (message, stacktrace) ->
|
68
|
+
lena(message, stacktrace, ['remote'])
|
69
|
+
|
70
|
+
# Log a message via Leña. Only logs to local (browser).
|
71
|
+
lena.local = (message, stacktrace) ->
|
72
|
+
lena(message, stacktrace, ['local'])
|
73
|
+
|
74
|
+
window.lena = lena
|
75
|
+
window.lena.onerror = window.onerror
|
76
|
+
window.onerror = (exception, url, linenum) ->
|
77
|
+
lena.log("#{exception}\nResource: #{url}:#{linenum}", null)
|
78
|
+
if lena.onerror then lena.onerror() else true
|
data/config/routes.rb
ADDED
data/lib/lena.rb
ADDED
data/lib/lena/engine.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'lena/rails/routing'
|
2
|
+
|
3
|
+
module Lena
|
4
|
+
class JavaScriptError < Exception; end
|
5
|
+
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
isolate_namespace Lena
|
8
|
+
initializer "lena.assets.precompile" do |app|
|
9
|
+
app.config.assets.precompile += %w(lena.js)
|
10
|
+
end
|
11
|
+
|
12
|
+
config.javascript_handler = Proc.new do
|
13
|
+
raise JavaScriptError.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.setup
|
18
|
+
yield Engine.config
|
19
|
+
end
|
20
|
+
end
|
data/lib/lena/routing.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Lena
|
2
|
+
# Extending the object that's returned from rails routing helpers (for
|
3
|
+
# instance +main_app+ or +lena+) that allow calling specific URL helper
|
4
|
+
# methods.
|
5
|
+
module Routing
|
6
|
+
def configuration
|
7
|
+
return {
|
8
|
+
'data-lena-destination' => Rails.env.development? ? "local" : "",
|
9
|
+
'data-lena-url' => self.submission_path,
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/lena/version.rb
ADDED
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require lena
|
14
|
+
//= require_tree .
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require "action_controller/railtie"
|
5
|
+
require "action_mailer/railtie"
|
6
|
+
require "sprockets/railtie"
|
7
|
+
|
8
|
+
Bundler.require(*Rails.groups)
|
9
|
+
require "lena"
|
10
|
+
|
11
|
+
module Dummy
|
12
|
+
class Application < Rails::Application
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
config.cache_classes = false
|
3
|
+
config.eager_load = false
|
4
|
+
config.consider_all_requests_local = true
|
5
|
+
config.action_controller.perform_caching = false
|
6
|
+
config.action_mailer.raise_delivery_errors = false
|
7
|
+
config.active_support.deprecation = :log
|
8
|
+
config.assets.debug = true
|
9
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
config.cache_classes = true
|
3
|
+
config.eager_load = false
|
4
|
+
config.serve_static_assets = true
|
5
|
+
config.static_cache_control = "public, max-age=3600"
|
6
|
+
config.consider_all_requests_local = true
|
7
|
+
config.action_controller.perform_caching = false
|
8
|
+
config.action_dispatch.show_exceptions = false
|
9
|
+
config.action_controller.allow_forgery_protection = false
|
10
|
+
config.action_mailer.delivery_method = :test
|
11
|
+
config.active_support.deprecation = :stderr
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rake secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure your secret_key_base is kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
Dummy::Application.config.secret_key_base = '71332c3167f676af35edf85850150c3d311af76e1888679e5b424459a8045ba9bdfcd07ddf39a45db4e11922ab74a14a5b6e7e82a5f1d8014affcfc266ecab74'
|