Logging, rolling file, permission denied

Hi,

I’m trying out the excellent logging 1.3.0 gem inside my rails
application. It works nicely with stdout and file appenders but I’m
unable to using the rolling file appender config. After running some
debug sessions I found out that the write fails due to i’m not sure
what, I am certain that the file path is valid, so I conclude it must
have to do with file locks…

By the way i’m running on windows XP.

The error:

Errno::EACCES Permission denied -
C:/rails_apps/fdc_psp_rails/log/development.log

The error is thrown from:

rolling_file.rb

def write( event )
str = event.instance_of?(::Logging::LogEvent) ?
@layout.format(event) : event.to_s
return if str.empty?

–> @io.flock_sh { super(str) } <–

  if roll_required?
    @io.flock? {
      @age_fn_mtime = nil
      copy_truncate if roll_required?
    }
    @roller.roll_files
  end
end

logging is integrated in rails environment.rb config likeso:

Logging.init :debug, :info, :warn, :error, :fatal

logger = Logging.logger.root
layout = Logging.layouts.pattern(:pattern => ‘%d %l [%.20c] %m’)
logger.add_appenders(
Logging.appenders.stdout(:layout => layout),
Logging.appenders.rolling_file(
“rolling_file”,
:filename => “#{RAILS_ROOT}/log/#{RAILS_ENV}.log”,
:age => ‘daily’,
:size => 2100000, # ~= 2mb
:layout => layout,
:level => :debug,
:safe => true
)
)
logger.level = :debug
config.logger = logger

I am using Mongrel but the rolling file also fails in webrick. The
result is that rolling_file logging level is set to :off…

Any help appreciated!
Thanks,
-Guillaume

Guillaume Guillaume wrote:

Hi,

I’m trying out the excellent logging 1.3.0 gem inside my rails
application. It works nicely with stdout and file appenders but I’m
unable to using the rolling file appender config. After running some
debug sessions I found out that the write fails due to i’m not sure
what, I am certain that the file path is valid, so I conclude it must
have to do with file locks…

Are you trying to log … Concurrently with the Rails log, or are you
trying to replace the default Rails logger with your own?
Look at this :
http://mikenaberezny.com/2007/02/24/rails-logging-tips/

Keeping this in mind:
One important point to remember is that the logfile object does not
implicitly flush to the file by default. This means that your code must
call logfile.flush for the data to be written out. Alternatively, you
can set logfile.sync = true to turn on implicit flushing.

Aldric G. wrote:

Guillaume Guillaume wrote:

Hi,

I’m trying out the excellent logging 1.3.0 gem inside my rails
application. It works nicely with stdout and file appenders but I’m
unable to using the rolling file appender config. After running some
debug sessions I found out that the write fails due to i’m not sure
what, I am certain that the file path is valid, so I conclude it must
have to do with file locks…

Are you trying to log … Concurrently with the Rails log, or are you
trying to replace the default Rails logger with your own?
Look at this :
Mike Naberezny – Rails Logging Tips

Keeping this in mind:
One important point to remember is that the logfile object does not
implicitly flush to the file by default. This means that your code must
call logfile.flush for the data to be written out. Alternatively, you
can set logfile.sync = true to turn on implicit flushing.

I am trying to replace Rails logger with the one from logging gem. There
are no attempts to log concurrently as far as I’m aware. However my
debugging session hints at 2 competing processes trying to log to the
same rolling file. If I use the regular file appender I don’t have that
exception. Only the rolling file setup throws the exception. It’s not a
problem with flushing, the exception thrown causes the rolling file
appender to get turned off with appender.level = :off.

Aldric G. wrote:

Guillaume Guillaume wrote:

I am trying to replace Rails logger with the one from logging gem. There
are no attempts to log concurrently as far as I’m aware. However my
debugging session hints at 2 competing processes trying to log to the
same rolling file. If I use the regular file appender I don’t have that
exception. Only the rolling file setup throws the exception. It’s not a
problem with flushing, the exception thrown causes the rolling file
appender to get turned off with appender.level = :off.

Did you write rolling_file.rb ? If not, which part of YOUR code is
calling the code that generates the error?

rolling_file.rb is part of logging gem, therefore I did not write it. It
is actually rails code that is calling the logger. The problem happens
whenever I start a mongrel instance with my rails 2.3.5 app. The
container is not a factor, the error also happens with webrick.

Guillaume Guillaume wrote:

I am trying to replace Rails logger with the one from logging gem. There
are no attempts to log concurrently as far as I’m aware. However my
debugging session hints at 2 competing processes trying to log to the
same rolling file. If I use the regular file appender I don’t have that
exception. Only the rolling file setup throws the exception. It’s not a
problem with flushing, the exception thrown causes the rolling file
appender to get turned off with appender.level = :off.

Did you write rolling_file.rb ? If not, which part of YOUR code is
calling the code that generates the error?

On Dec 23, 2009, at 1:25 PM, Guillaume Guillaume wrote:

Someone pointed out this thread to me just yesterday. Sorry that I
missed it when it first popped up back around Christmas time.

I opened an issue for this problem:

It will be fixed in the next release of the Logging gem (sometime
today).

Blessings,
TwP