ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:49036] [ruby-trunk - Bug #7303][Open] Logger fails on log rotation in Windows (log shifting failed. Permission denied)
@ 2012-11-07 14:40 pink-ink (Herman Munster)
  2012-11-07 14:44 ` [ruby-core:49037] [ruby-trunk - Bug #7303] " pink-ink (Herman Munster)
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: pink-ink (Herman Munster) @ 2012-11-07 14:40 UTC (permalink / raw)
  To: ruby-core


Issue #7303 has been reported by pink-ink (Herman Munster).

----------------------------------------
Bug #7303: Logger fails on log rotation in Windows (log shifting failed. Permission denied)
https://bugs.ruby-lang.org/issues/7303

Author: pink-ink (Herman Munster)
Status: Open
Priority: Normal
Assignee: nahi (Hiroshi Nakamura)
Category: lib
Target version: 
ruby -v: ruby 1.9.3p0 (2011-10-30) [i386-mingw32]


I have the problem that the logger fails in rotating the log file (daily) with Ruby 1.9.3 in Windows 7.

The cause is, that the log file is open and shall be renamed.
This results in an error "log shifting failed. Permission denied".

Log rotating will work, if the log file is copied to the age_file and then the logfile is cleaned by using logdev.truncate(0).

My changes to logger.rb are (remove 3 lines, add 2 lines):

    def shift_log_period(period_end)
      postfix = period_end.strftime("%Y%m%d")# YYYYMMDD
      age_file = "#{@filename}.#{postfix}"
      if FileTest.exist?(age_file)
        # try to avoid filename crash caused by Timestamp change.
        idx = 0
        # .99 can be overridden; avoid too much file search with 'loop do'
        while idx < 100
          idx += 1
          age_file = "#{@filename}.#{postfix}.#{idx}"
          break unless FileTest.exist?(age_file)
        end
      end
-     @dev.close rescue nil
-     File.rename("#{@filename}", age_file)
-     @dev = create_logfile(@filename)
+     FileUtils.cp(@filename, age_file)
+     reset_logfile(@dev)  # see below for this new method
      return true

I've added a new method to clean the open logfile and add a log header:
    def reset_logfile(logdev)
      logdev.truncate( 0 )
      logdev.sync = true
      add_log_header(logdev)
    end

The change above (copy/clean instead of rename) should also be
applied to the method "shift_log_age", same problem here.

I don't know how to bring this code into standard ruby sources.
Please somebody change the code, so the bug will be fixed.

(I found this bug also described in the old RubyForge archive: http://rubyforge.org/tracker/?group_id=426&atid=1698&func=detail&aid=19709)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:49037] [ruby-trunk - Bug #7303] Logger fails on log rotation in Windows (log shifting failed. Permission denied)
  2012-11-07 14:40 [ruby-core:49036] [ruby-trunk - Bug #7303][Open] Logger fails on log rotation in Windows (log shifting failed. Permission denied) pink-ink (Herman Munster)
@ 2012-11-07 14:44 ` pink-ink (Herman Munster)
  2012-12-21 13:21 ` [ruby-core:51043] [ruby-trunk - Bug #7303][Assigned] " usa (Usaku NAKAMURA)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pink-ink (Herman Munster) @ 2012-11-07 14:44 UTC (permalink / raw)
  To: ruby-core


Issue #7303 has been updated by pink-ink (Herman Munster).


Addition to my previous post:
require 'fileutils' is needed at the beginning of logger.rb, if using FileUtils.cp().
----------------------------------------
Bug #7303: Logger fails on log rotation in Windows (log shifting failed. Permission denied)
https://bugs.ruby-lang.org/issues/7303#change-32565

Author: pink-ink (Herman Munster)
Status: Open
Priority: Normal
Assignee: nahi (Hiroshi Nakamura)
Category: lib
Target version: 
ruby -v: ruby 1.9.3p0 (2011-10-30) [i386-mingw32]


I have the problem that the logger fails in rotating the log file (daily) with Ruby 1.9.3 in Windows 7.

The cause is, that the log file is open and shall be renamed.
This results in an error "log shifting failed. Permission denied".

Log rotating will work, if the log file is copied to the age_file and then the logfile is cleaned by using logdev.truncate(0).

My changes to logger.rb are (remove 3 lines, add 2 lines):

    def shift_log_period(period_end)
      postfix = period_end.strftime("%Y%m%d")# YYYYMMDD
      age_file = "#{@filename}.#{postfix}"
      if FileTest.exist?(age_file)
        # try to avoid filename crash caused by Timestamp change.
        idx = 0
        # .99 can be overridden; avoid too much file search with 'loop do'
        while idx < 100
          idx += 1
          age_file = "#{@filename}.#{postfix}.#{idx}"
          break unless FileTest.exist?(age_file)
        end
      end
-     @dev.close rescue nil
-     File.rename("#{@filename}", age_file)
-     @dev = create_logfile(@filename)
+     FileUtils.cp(@filename, age_file)
+     reset_logfile(@dev)  # see below for this new method
      return true

I've added a new method to clean the open logfile and add a log header:
    def reset_logfile(logdev)
      logdev.truncate( 0 )
      logdev.sync = true
      add_log_header(logdev)
    end

The change above (copy/clean instead of rename) should also be
applied to the method "shift_log_age", same problem here.

I don't know how to bring this code into standard ruby sources.
Please somebody change the code, so the bug will be fixed.

(I found this bug also described in the old RubyForge archive: http://rubyforge.org/tracker/?group_id=426&atid=1698&func=detail&aid=19709)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:51043] [ruby-trunk - Bug #7303][Assigned] Logger fails on log rotation in Windows (log shifting failed. Permission denied)
  2012-11-07 14:40 [ruby-core:49036] [ruby-trunk - Bug #7303][Open] Logger fails on log rotation in Windows (log shifting failed. Permission denied) pink-ink (Herman Munster)
  2012-11-07 14:44 ` [ruby-core:49037] [ruby-trunk - Bug #7303] " pink-ink (Herman Munster)
@ 2012-12-21 13:21 ` usa (Usaku NAKAMURA)
  2019-07-23 15:11 ` [ruby-core:93888] [Ruby master Bug#7303] " hsbt
  2019-08-17  3:46 ` [ruby-core:94398] " sonots
  3 siblings, 0 replies; 5+ messages in thread
From: usa (Usaku NAKAMURA) @ 2012-12-21 13:21 UTC (permalink / raw)
  To: ruby-core


Issue #7303 has been updated by usa (Usaku NAKAMURA).

Status changed from Open to Assigned


----------------------------------------
Bug #7303: Logger fails on log rotation in Windows (log shifting failed. Permission denied)
https://bugs.ruby-lang.org/issues/7303#change-34949

Author: pink-ink (Herman Munster)
Status: Assigned
Priority: Normal
Assignee: nahi (Hiroshi Nakamura)
Category: lib
Target version: 
ruby -v: ruby 1.9.3p0 (2011-10-30) [i386-mingw32]


I have the problem that the logger fails in rotating the log file (daily) with Ruby 1.9.3 in Windows 7.

The cause is, that the log file is open and shall be renamed.
This results in an error "log shifting failed. Permission denied".

Log rotating will work, if the log file is copied to the age_file and then the logfile is cleaned by using logdev.truncate(0).

My changes to logger.rb are (remove 3 lines, add 2 lines):

    def shift_log_period(period_end)
      postfix = period_end.strftime("%Y%m%d")# YYYYMMDD
      age_file = "#{@filename}.#{postfix}"
      if FileTest.exist?(age_file)
        # try to avoid filename crash caused by Timestamp change.
        idx = 0
        # .99 can be overridden; avoid too much file search with 'loop do'
        while idx < 100
          idx += 1
          age_file = "#{@filename}.#{postfix}.#{idx}"
          break unless FileTest.exist?(age_file)
        end
      end
-     @dev.close rescue nil
-     File.rename("#{@filename}", age_file)
-     @dev = create_logfile(@filename)
+     FileUtils.cp(@filename, age_file)
+     reset_logfile(@dev)  # see below for this new method
      return true

I've added a new method to clean the open logfile and add a log header:
    def reset_logfile(logdev)
      logdev.truncate( 0 )
      logdev.sync = true
      add_log_header(logdev)
    end

The change above (copy/clean instead of rename) should also be
applied to the method "shift_log_age", same problem here.

I don't know how to bring this code into standard ruby sources.
Please somebody change the code, so the bug will be fixed.

(I found this bug also described in the old RubyForge archive: http://rubyforge.org/tracker/?group_id=426&atid=1698&func=detail&aid=19709)


-- 
http://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:93888] [Ruby master Bug#7303] Logger fails on log rotation in Windows (log shifting failed. Permission denied)
  2012-11-07 14:40 [ruby-core:49036] [ruby-trunk - Bug #7303][Open] Logger fails on log rotation in Windows (log shifting failed. Permission denied) pink-ink (Herman Munster)
  2012-11-07 14:44 ` [ruby-core:49037] [ruby-trunk - Bug #7303] " pink-ink (Herman Munster)
  2012-12-21 13:21 ` [ruby-core:51043] [ruby-trunk - Bug #7303][Assigned] " usa (Usaku NAKAMURA)
@ 2019-07-23 15:11 ` hsbt
  2019-08-17  3:46 ` [ruby-core:94398] " sonots
  3 siblings, 0 replies; 5+ messages in thread
From: hsbt @ 2019-07-23 15:11 UTC (permalink / raw)
  To: ruby-core

Issue #7303 has been updated by hsbt (Hiroshi SHIBATA).

Assignee changed from nahi (Hiroshi Nakamura) to sonots (Naotoshi Seo)
Description updated

----------------------------------------
Bug #7303: Logger fails on log rotation in Windows (log shifting failed. Permission denied)
https://bugs.ruby-lang.org/issues/7303#change-79873

* Author: pink-ink (Herman Munster)
* Status: Assigned
* Priority: Normal
* Assignee: sonots (Naotoshi Seo)
* Target version: 
* ruby -v: ruby 1.9.3p0 (2011-10-30) [i386-mingw32]
* Backport: 
----------------------------------------
I have the problem that the logger fails in rotating the log file (daily) with Ruby 1.9.3 in Windows 7.

The cause is, that the log file is open and shall be renamed.
This results in an error "log shifting failed. Permission denied".

Log rotating will work, if the log file is copied to the age_file and then the logfile is cleaned by using logdev.truncate(0).

My changes to logger.rb are (remove 3 lines, add 2 lines):

```
    def shift_log_period(period_end)
      postfix = period_end.strftime("%Y%m%d")# YYYYMMDD
      age_file = "#{@filename}.#{postfix}"
      if FileTest.exist?(age_file)
        # try to avoid filename crash caused by Timestamp change.
        idx = 0
        # .99 can be overridden; avoid too much file search with 'loop do'
        while idx < 100
          idx += 1
          age_file = "#{@filename}.#{postfix}.#{idx}"
          break unless FileTest.exist?(age_file)
        end
      end
-     @dev.close rescue nil
-     File.rename("#{@filename}", age_file)
-     @dev = create_logfile(@filename)
+     FileUtils.cp(@filename, age_file)
+     reset_logfile(@dev)  # see below for this new method
      return true
```

I've added a new method to clean the open logfile and add a log header:

```
    def reset_logfile(logdev)
      logdev.truncate( 0 )
      logdev.sync = true
      add_log_header(logdev)
    end
```

The change above (copy/clean instead of rename) should also be
applied to the method "shift_log_age", same problem here.

I don't know how to bring this code into standard ruby sources.
Please somebody change the code, so the bug will be fixed.

(I found this bug also described in the old RubyForge archive: http://rubyforge.org/tracker/?group_id=426&atid=1698&func=detail&aid=19709)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:94398] [Ruby master Bug#7303] Logger fails on log rotation in Windows (log shifting failed. Permission denied)
  2012-11-07 14:40 [ruby-core:49036] [ruby-trunk - Bug #7303][Open] Logger fails on log rotation in Windows (log shifting failed. Permission denied) pink-ink (Herman Munster)
                   ` (2 preceding siblings ...)
  2019-07-23 15:11 ` [ruby-core:93888] [Ruby master Bug#7303] " hsbt
@ 2019-08-17  3:46 ` sonots
  3 siblings, 0 replies; 5+ messages in thread
From: sonots @ 2019-08-17  3:46 UTC (permalink / raw)
  To: ruby-core

Issue #7303 has been updated by sonots (Naotoshi Seo).


It looks the codes around specified are fairly changed from 1.9.3 now. This problem should already have been fixed.
Let me close once. If anyone finds same issue with the latest ruby, please let me know.

----------------------------------------
Bug #7303: Logger fails on log rotation in Windows (log shifting failed. Permission denied)
https://bugs.ruby-lang.org/issues/7303#change-80817

* Author: pink-ink (Herman Munster)
* Status: Assigned
* Priority: Normal
* Assignee: sonots (Naotoshi Seo)
* Target version: 
* ruby -v: ruby 1.9.3p0 (2011-10-30) [i386-mingw32]
* Backport: 
----------------------------------------
I have the problem that the logger fails in rotating the log file (daily) with Ruby 1.9.3 in Windows 7.

The cause is, that the log file is open and shall be renamed.
This results in an error "log shifting failed. Permission denied".

Log rotating will work, if the log file is copied to the age_file and then the logfile is cleaned by using logdev.truncate(0).

My changes to logger.rb are (remove 3 lines, add 2 lines):

```
    def shift_log_period(period_end)
      postfix = period_end.strftime("%Y%m%d")# YYYYMMDD
      age_file = "#{@filename}.#{postfix}"
      if FileTest.exist?(age_file)
        # try to avoid filename crash caused by Timestamp change.
        idx = 0
        # .99 can be overridden; avoid too much file search with 'loop do'
        while idx < 100
          idx += 1
          age_file = "#{@filename}.#{postfix}.#{idx}"
          break unless FileTest.exist?(age_file)
        end
      end
-     @dev.close rescue nil
-     File.rename("#{@filename}", age_file)
-     @dev = create_logfile(@filename)
+     FileUtils.cp(@filename, age_file)
+     reset_logfile(@dev)  # see below for this new method
      return true
```

I've added a new method to clean the open logfile and add a log header:

```
    def reset_logfile(logdev)
      logdev.truncate( 0 )
      logdev.sync = true
      add_log_header(logdev)
    end
```

The change above (copy/clean instead of rename) should also be
applied to the method "shift_log_age", same problem here.

I don't know how to bring this code into standard ruby sources.
Please somebody change the code, so the bug will be fixed.

(I found this bug also described in the old RubyForge archive: http://rubyforge.org/tracker/?group_id=426&atid=1698&func=detail&aid=19709)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-17  3:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-07 14:40 [ruby-core:49036] [ruby-trunk - Bug #7303][Open] Logger fails on log rotation in Windows (log shifting failed. Permission denied) pink-ink (Herman Munster)
2012-11-07 14:44 ` [ruby-core:49037] [ruby-trunk - Bug #7303] " pink-ink (Herman Munster)
2012-12-21 13:21 ` [ruby-core:51043] [ruby-trunk - Bug #7303][Assigned] " usa (Usaku NAKAMURA)
2019-07-23 15:11 ` [ruby-core:93888] [Ruby master Bug#7303] " hsbt
2019-08-17  3:46 ` [ruby-core:94398] " sonots

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).