#---------------lib/app_logger.rb------------
require 'logger'
class AppLogger
  attr_writer :man_name, :emp_name

  def initialize(man_name, emp_name)
    @man_name = man_name
    @emp_name = emp_name

    log_path = "log/"
    file_name = "file.log"
    log_level = "ACTIVITY"

   log_file = log_path + file_name
   @logger = Logger.new(log_file, 'daily')

    case log_level
    when "DEBUG"
      @level = Logger::DEBUG
    when "INFO"
      @level = Logger::INFO
    when "WARN"
      @level = Logger::WARN
    when "ERROR"
      @level = Logger::ERROR
    when "FATAL"
      @level = Logger::FATAL
    else
      @level = Logger::UNKNOWN
    end

  end

  def close
    @logger.close if @logger
  end

  def debug(msg)
    log_message(Logger::DEBUG, msg)
  end

  def info(msg)
    log_message(Logger::INFO, msg)
  end

  def warn(msg)
    log_message(Logger::WARN, msg)
  end

  def error(msg)
    log_message(Logger::ERROR, msg)
  end

  def fatal(msg)
    log_message(Logger::FATAL, msg)
  end

  def activity(msg)
    log_message(Logger::UNKNOWN, msg)
  end

private
  SEV_LABEL = %w(DEBUG INFO WARN ERROR FATAL UNKNOWN)
  def log_message(severity, msg)
    if @logger.nil? or severity < @level
      return true
    end
    fmt_msg = "#...@man_name} | #...@emp_name} | #{Time.now.strftime("%Y-
%m-%d %H:%M:%S")} | #{SEV_LABEL[severity]} | #{msg}\r\n"
    @logger << fmt_msg
  end
end
#-----------------------------------------------------------

Above logger Code is present in lib folder, named logger.rb

i have included ---before_filter :init_logger-- this piece of code in
all controllers

in application.rb

  def init_logger
    unless $app_logger
      man_name = "mPowerForce"
      emp_name = "mPowerSales"
      $app_logger = AppLogger.new(man_name, emp_name)
    end
  end


rails version --->2.1.1

am running my rails application as three instances in three consequent
ports
on the first day no problem in creating file.log and next day when
application is running in 1st instance its creating a backup of
file.log as file_previous_date.log when its running in the 2nd
instance on the same day

The following error occurred
Logger::ShiftingError in controller
Shifting failed. closed stream

Could any one give a solution for this problem

Thanx in advance

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to