Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
139 lines (93 sloc) 3.35 KB

What is that for?

Rails engine to log from Client side (Browser) javascript to server log file. To catch those nasty production Javascript errors. Provides a variety of safe logging functions e.g. jsLogger.debug(), jsLogger.error().

There are 5 levels of logging: debug, info, warn, error and fatal.

If exception_notification is found, sends notifications for error and fatal levels.

Supports Rails 4 (permitted parameters).

For Rails 3.x use gem version 0.0.2.

Gem Version


Add this line to your application's Gemfile:

For Rails 4.x

gem 'rails-client-logger'

For Rails 3.x

gem 'rails-client-logger', '0.0.2'

And then execute:

$ bundle install

Then simply execute following generator command. It inserts the required routes and javascript files and you're ready to rock!

$ rails g rails_client_logger


Logging a message"simple info message");
jsLogger.warn("a warning");

Log Error

try {
    throw new Error('unhandled exception');
catch (e) {

Log all unhandled javascript errors:

window.onerror = function (message, url, line_number) {
  jsLogger.fatal("Uncaught error in: " + url + ":" + line_number + "\nDetails: " + message);

View Logs

The logged messages will appear in the normal rails log (i.e. development.log or staging.log or production.log).


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.


  1. Create a new controller logger_controller.rb that inherits from RailsClientLoggersController like this:

    class LoggerController < RailsClientLogger::RailsClientLoggersController
  2. Add a new route in routes.rb

    match 'logger/rails_client_logger/log' => 'logger#log'
    mount RailsClientLogger::Engine, :at => "logger"

Namespaced Logger URL

In case you need more flexibility with the url handling, for example if you have an API only app.

  1. Modify routes.rb to include namespaced API routes
namespace :api do
  namespace :v1 do
    mount RailsClientLogger::Engine, :at => "apilogger"
  1. Specify global vars like
window.jsLoggerBasePath = "/api/v1"
window.jsLoggerUrl = "/apilogger/rails_client_logger/log"


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request


meghali - for the idea

girishso - for the implementation

elthariel - for Rails 4 support and CoffeeScript implementation

rhino232 - for namespaced URLs


MIT License

Copyright (c) 2013 Girish Sonawane (girish dot sonawane at gmail dot com)

Jump to Line
Something went wrong with that request. Please try again.