Project

lena

0.0
No commit activity in last 3 years
No release in over 3 years
Remote JavaScript logging for Rails applications.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 4.0.0
~> 4.0.0
 Project Readme

Leña Gem Version Build Status Code Review Code Coverage

Leña generates reports of client-side JavaScript errors in production Rails applications by sending error details to the server. This allows for better tracking of errors that occur in front-end code.

Installation

Add lena to your Gemfile, then bundle install.

Add the following to your application.js:

//= require lena

Add the following to your routes.rb:

mount Lena::Engine => "/lena"

Update your application.html.erb:

<%= javascript_include_tag "application", :data => lena.configuration %>

Usage Client Side

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:

lena.log('My Error Message')

Usage Server Side

Leña will throw an exception, Lena::ClientError, when it receives a log message. Why? Because you're probably already using some sort of error reporting. Also that's basically what's happening on the client side, so why not throw an exception on the server?

If you need to configure what Leña does, you can add an initializer, config/initializers/lena.rb:

Lena.setup do |config|
  config.report_handler = Proc.new do |params|
    # Custom handling of log message here
  end
end

Customization

An alternative to setting up Leña on your application.js file is to import Leña separately. This may impact performance slightly, but it will catch compiler errors in any scripts included after it:

<%= javascript_include_tag "lena", :data => lena.configuration %>

It is also possible to change the way that Leña handles logging on the client side. This is done by altering the options on the JavasScript include tag:

<%= javascript_include_tag "lena", :data => lena.configuration.merge("option" => "value") %>

The following options are available:

  • lena-destination The destination to report errors. The value is one of:
    • local Report errors to the console (if available).
    • remote Report errors to the server.
    • all Report errors to all supported destinations (local & remote). This defaults to local during development and all for production & test.
  • lena-remote-url A url to which Leña will errors. You can change this to point to another location or service if need be.

License

This project is distributed under the MIT license.