Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best Rails Logging Gem

what is the best way of configuring Logging features on a rails project? I'm looking for something like Log4J which is available to Rails. I have found log4r and it's conflicting built in Logger class and also tried 'Logging' gem and It has some issues configuring as a audit logger. Please let me know your suggestions on this topic since I'm a beginner on the subject.

I have used below code block in logging.rb and included in environment.rb But I'm receiving a error on 'returning' keyword as it's deprecated on rails 2.8

config/environment.rb

# Logging
require File.join(File.dirname(__FILE__), 'logging')

Rails::Initializer.run do |config|

config/logging.rb

require 'logging'

# Logging.init is required to avoid 
#   unknown level was given 'info' (ArgumentError)
# or
#   uninitialized constant Logging::MAX_LEVEL_LENGTH (NameError)
# when an Appender or Layout is created BEFORE any Logger is instantiated:
Logging.init :debug, :info, :warn, :error, :fatal

layout = Logging::Layouts::Pattern.new :pattern => "[%d] [%-5l] %m\n"

# Default logfile, history kept for 10 days
default_appender = Logging::Appenders::RollingFile.new 'default', \
  :filename => 'log/default.log', :age => 'daily', :keep => 10, :safe => true, :layout => layout

# Audit logfile, history kept forever
audit_appender = Logging::Appenders::RollingFile.new 'audit', \
  :filename => 'log/audit.log', :age => 'daily', :safe => true, :layout => layout

# Production logfile, history kept forever
prod_appender = Logging::Appenders::RollingFile.new 'prod', \
  :filename => 'log/production.log', :age => 'daily', :safe => true, :layout => layout

DEFAULT_LOGGER = returning Logging::Logger['server'] do |l|
  l.add_appenders default_appender
end
like image 223
Pradeep Sanjaya Avatar asked Jul 26 '11 17:07

Pradeep Sanjaya


1 Answers

Have a look at the following threads:

Rails Logging API

logging in rails app

What's a good logging replacement for rails?

like image 107
sameera207 Avatar answered Sep 28 '22 05:09

sameera207