Menu

logrotate utility for Windows Platform - fails if filename prefix contains a number

2015-04-08
2016-04-08
1 2 > >> (Page 1 of 2)
  • Chris Thorp

    Chris Thorp - 2015-04-08

    Hi,

    If the target filename for rotation contains a number i.e. “server1.out” then rotation will fail:

    logrotate: Rotate will be simulated because Debug is true
    logrotate: Exception: Input string was not in a correct format.
    logrotate: StackTrace: at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, Number
    FormatInfo info, Boolean parseDecimal)
    at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
    at logrotate.Program.AgeOutRotatedFiles(logrotateconf lrc, FileInfo fi, String rotate_path)
    at logrotate.Program.RotateFile(logrotateconf lrc, FileInfo fi)
    at logrotate.Program.Main(String[] args)

    I have seen this error on the review page and I suspect this is the cause. I want to use this utility but we have numbered WLS servers. Any chance of a fix please.

    regards,
    Chris

     
  • Ken Salter

    Ken Salter - 2015-04-08

    Hi Chris: I will take a a look at this and reply here when I find something.

     
  • Ken Salter

    Ken Salter - 2015-04-08

    Chris, can you post your conf file? I am trying to duplicate this but apparently there is a conf config you are using that is causing this, and I need to see it. Thanks.

     
  • Chris Thorp

    Chris Thorp - 2015-04-08

    Ken,

    Attached config file.

    regards,
    Chris

     
  • Chris Thorp

    Chris Thorp - 2015-04-08

    This is the complete command + error:

    H:\LogRotate>logrotate.exe -s logrotate.status -d -v -f Content\logrotate.conf
    logrotate: Debug option set to true
    logrotate: Verbose option set to true
    logrotate: Verbose option set to true
    logrotate: Force option set to true
    logrotate: Content\logrotate.conf Adding to config files to process
    logrotate: Parsing configuraiton file Content\logrotate.conf
    logrotate: read line # sample logrotate configuration file
    logrotate: Skipping comment
    logrotate: read line
    logrotate: read line # uncomment to enable compression of rotated log files
    logrotate: Skipping comment
    logrotate: read line # compress
    logrotate: Skipping comment
    logrotate: read line copytruncate
    logrotate: Setting copytruncate to True
    logrotate: read line
    logrotate: read line # this example will rotate the c:\test.log file daily and keep 5 rotations.
    logrotate: Skipping comment
    logrotate: read line # there is also an example prerotate script that will print the current time and the parameter pass
    ed to it (which is the path to the log file)
    logrotate: Skipping comment
    logrotate: read line #h:\LogRotate\test.out {
    logrotate: Skipping comment
    logrotate: read line h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out {
    logrotate: Processing new section
    logrotate: read line #H:\bea\dummy\Server1\logs\Server1.out {
    logrotate: Skipping comment
    logrotate: read line daily
    logrotate: Setting daily to True
    logrotate: read line rotate 10
    logrotate: Setting rotate to 10
    logrotate: read line }
    logrotate: Processing h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Force option is set, will rotate
    logrotate: Rotating file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Rotate will be simulated because Debug is true
    logrotate: Exception: Input string was not in a correct format.
    logrotate: StackTrace: at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, Number
    FormatInfo info, Boolean parseDecimal)
    at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
    at logrotate.Program.AgeOutRotatedFiles(logrotateconf lrc, FileInfo fi, String rotate_path)
    at logrotate.Program.RotateFile(logrotateconf lrc, FileInfo fi)
    at logrotate.Program.Main(String[] args)

     
  • Ken Salter

    Ken Salter - 2015-04-08

    What is the name of the log files that have already been rotated?

     
  • Chris Thorp

    Chris Thorp - 2015-04-08

    When you deploy a new EAR then WLS rotates the file to be <servername>.outNNNNN
    e.g. DMSServer1.out00001, DMSServer1.out00002,...... DMSServer1.out0000n.

    When I delete these then it works.

     
  • Chris Thorp

    Chris Thorp - 2015-04-08

    ...Although can't rotate as process is open by JVM :-(

    H:\LogRotate>logrotate.exe -s logrotate.status -v -f Content\logrotate.conf
    logrotate: Verbose option set to true
    logrotate: Force option set to true
    logrotate: Content\logrotate.conf Adding to config files to process
    logrotate: Parsing configuraiton file Content\logrotate.conf
    logrotate: Processing new section
    logrotate: Processing h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Force option is set, will rotate
    logrotate: Rotating file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Copying h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out to h:\bea\user_project
    s\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.1
    logrotate: Truncating original log file
    logrotate: Error truncating file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Exception: The process cannot access the file 'h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\log
    s\DMSServer1.out' because it is being used by another process.
    logrotate: StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShar
    e share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
    at logrotate.Program.RotateFile(logrotateconf lrc, FileInfo fi)

    Sorry to be a pain about this !

     
  • Ken Salter

    Ken Salter - 2015-04-08

    Hah you're not being a pain...thanks for the info will take a look at it.

     
  • Ken Salter

    Ken Salter - 2015-04-08

    I just posted a new update...let me know if this works for you

     
  • Chris Thorp

    Chris Thorp - 2015-04-09

    Ken,

    If file exists in format DMSServer1.out00001 then I get:

    H:\LogRotate>logrotate.exe -s logrotate.status -v -f Content\logrotate.conf
    logrotate: logrotate 0.0.0.14 - Copyright (C) 2012-2013 Ken Salter
    logrotate: Verbose option set to true
    logrotate: Force option set to true
    logrotate: Content\logrotate.conf Adding to config files to process
    logrotate: Parsing configuraiton file Content\logrotate.conf
    logrotate: Processing new section
    logrotate: Processing h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Force option is set, will rotate
    logrotate: Rotating file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Exception: Input string was not in a correct format.
    logrotate: StackTrace: at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, Number
    FormatInfo info, Boolean parseDecimal)
    at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
    at logrotate.Program.AgeOutRotatedFiles(logrotateconf lrc, FileInfo fi, String rotate_path)
    at logrotate.Program.RotateFile(logrotateconf lrc, FileInfo fi)
    at logrotate.Program.Main(String[] args)

    If I delete this file then I get :

    H:\LogRotate>logrotate.exe -s logrotate.status -v -f Content\logrotate.conf
    logrotate: logrotate 0.0.0.14 - Copyright (C) 2012-2013 Ken Salter
    logrotate: Verbose option set to true
    logrotate: Force option set to true
    logrotate: Content\logrotate.conf Adding to config files to process
    logrotate: Parsing configuraiton file Content\logrotate.conf
    logrotate: Processing new section
    logrotate: Processing h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Force option is set, will rotate
    logrotate: Rotating file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Renaming h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.1 to h:\bea\user_proj
    ects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.2
    logrotate: Compressing rotated log file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.2

    logrotate: Deleting file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.2
    logrotate: Copying h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out to h:\bea\user_project
    s\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.1
    logrotate: Truncating original log file
    logrotate: Error truncating file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Exception: The process cannot access the file 'h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\log
    s\DMSServer1.out' because it is being used by another process.
    logrotate: StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShar
    e share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
    at logrotate.Program.RotateFile(logrotateconf lrc, FileInfo fi)

     
  • Ken Salter

    Ken Salter - 2015-04-09

    Hmm, I'm curious why I can't duplicate this...I will take another look.

     
  • Ken Salter

    Ken Salter - 2015-04-09

    Also, if another process has the file locked, logrotate will not be able to truncate it. Right now it just logs the error that it cannot get access. What are you expecting to happen?

     
  • Ken Salter

    Ken Salter - 2015-04-09

    Here is a debug version...can you run it in both scenarios and post the output?

     
  • Chris Thorp

    Chris Thorp - 2015-04-09

    Ken,

    I would expect the copytruncate flag fix (as discussed https://sourceforge.net/p/logrotatewin/discussion/general/thread/2fa14b0a/#275e) to truncate the open file.
    I seem to be getting the same error though. Please correct me if this is not the case.
    Here you go with the debug.....

    Scenario 1:

    H:\LogRotate>logrotate.exe -s logrotate.status -v -f Content\logrotate.conf
    logrotate: logrotate 0.0.0.15 - Copyright (C) 2012-2013 Ken Salter
    logrotate: Verbose option set to true
    logrotate: Force option set to true
    logrotate: Content\logrotate.conf Adding to config files to process
    logrotate: Parsing configuration file Content\logrotate.conf
    logrotate: Processing new section
    logrotate: Processing h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Force option is set, will rotate
    logrotate: Rotating file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Examining filename DMSServer1.out00001
    logrotate: Parsing out00001
    logrotate: Unable to parse DMSServer1 as an int32, skipping...
    logrotate: Examining filename DMSServer1.out.3.gz
    logrotate: Parsing gz
    logrotate: Parsing 3
    logrotate: Renaming h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.3.gz to h:\bea\user_p
    rojects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.4.gz
    logrotate: Examining filename DMSServer1.out.2.gz
    logrotate: Parsing gz
    logrotate: Parsing 2
    logrotate: Renaming h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.2.gz to h:\bea\user_p
    rojects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.3.gz
    logrotate: Examining filename DMSServer1.out.1
    logrotate: Parsing 1
    logrotate: Renaming h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.1 to h:\bea\user_proj
    ects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.2
    logrotate: Compressing rotated log file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.2

    logrotate: Deleting file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.2
    logrotate: Copying h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out to h:\bea\user_project
    s\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.1
    logrotate: Truncating original log file
    logrotate: Error truncating file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: The process cannot access the file 'h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer
    1.out' because it is being used by another process.
    logrotate: Compressing rotated log file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.1

    logrotate: Deleting file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.1
    logrotate: Updating rotation date in status file

    Scenario 2:

    H:\LogRotate>logrotate.exe -s logrotate.status -v -f Content\logrotate.conf
    logrotate: logrotate 0.0.0.15 - Copyright (C) 2012-2013 Ken Salter
    logrotate: Verbose option set to true
    logrotate: Force option set to true
    logrotate: Content\logrotate.conf Adding to config files to process
    logrotate: Parsing configuration file Content\logrotate.conf
    logrotate: Processing new section
    logrotate: Processing h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Force option is set, will rotate
    logrotate: Rotating file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: Copying h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out to h:\bea\user_project
    s\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.1
    logrotate: Truncating original log file
    logrotate: Error truncating file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out
    logrotate: The process cannot access the file 'h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer
    1.out' because it is being used by another process.
    logrotate: Compressing rotated log file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.1

    logrotate: Deleting file h:\bea\user_projects\domains\DMS_domain\servers\DMSServer1\logs\DMSServer1.out.1
    logrotate: Updating rotation date in status file

     
  • Ken Salter

    Ken Salter - 2015-04-09

    Okay from this I see that I was able to handle not being able to parse the DMSServer1.out00001 file.

    As to the truncate, if another process has a lock on the file, there is nothing I can do. I can duplicate this by opening the log file with Microsoft Word, which locks the file completely.

    The fix you mention was to opening the file in a share mode, but if another process has it locked even in this mode, I cannot do anything about it.

    I was thinking of adding a new conf option to allow the program to retry getting access the file...but in your case I don't know what kind of program has the log file open. If it has it open and locked continuously then it won't do any good. But if it opens, locks, and then closes maybe with retries I can get access to the file to truncate it.

    What do you think?

     
  • Ken Salter

    Ken Salter - 2015-04-10

    Okay, here is a new test version where I have added 3 new conf entries to help with retrying to open the file.

    logfileopen_retry - will attempt to retry opening the log file for truncation or renaming. Default is false.

    logfileopen_numretryattempts - number of attempts before giving up. Default is 0 which means never give up.

    logfileopen_msbetweenretryattempts - amount of time between retries in ms. Default is 1000.

    Here is a sample conf file:

    copytruncate
    logfileopen_retry
    logfileopen_numretryattempts 3
    logfileopen_msbetweenretryattempts 5000

    J:\logrotate\test1\test1.out {
    daily
    rotate 2
    }

    Would this help you?

     
  • Dom

    Dom - 2015-07-21

    Just curious if there was any update on this (the number in the filename, not the file lock which looks like it has a good solution/workaround from Ken)?

    I'm also getting the same issue using logrotate 0.0.0.14, and taking a quick look at the source code seems to happen on the ToInt32 line below from AgeOutRotatedFiles, or at least does when I run it in Visual Studio.

    if (Convert.ToInt32(exts[i]) >= lrc.Rotate)
    {
    // too old!

    Additional output from the command line

    logrotate: Exception: Input string was not in a correct format.
    logrotate: StackTrace: at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, Number
    FormatInfo info, Boolean parseDecimal)
    at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
    at System.Convert.ToInt32(String value)
    at logrotate.Program.AgeOutRotatedFiles(logrotateconf lrc, FileInfo fi, String rotate_path) in c:\logrotate\Program.cs:line 733
    at logrotate.Program.RotateFile(logrotateconf lrc, FileInfo fi) in c:\logrotate\Program.cs:line 801
    at logrotate.Program.Main(String[] args) in c:\logrotate\Program.cs:line 192

    If anyone else wants to reproduce it then here is my setup (make sure you delete the rotate.status file if you run it multiple times for a proper clean run)...

    Create a folder called C:\Temp\LogTest
    Create the following files in the folder

    TEST_L6.OUT
    TEST_L6.OUT_004
    TEST_L6.OUT_005

    Create/edit a logstatus.conf file so that has the following contents

    C:\Temp\LogTest*.OUT {
    rotate 7
    daily
    nocompress
    }

    Then run logrotate in the usual manner e.g. logrotate.exe -s c:\temp\rotate.status logrotate.conf -v

    Debugging in Visual Studio, it errors as it tries to convert TEST_L6 to an integer and fails. I initially thought using int.TryParse or similar logic would fix it but it is not just the filename as if you remove the .OUT_004 and .OUT_005 files then it works OK so there must obviously be other logic at play which would take me a little longer to unpick!

    Hopefully this will help diagnose the issue and let me know if you need any more info - appreciate the work that's been done on a very nice little utility!

    Dom

     
  • Ken Salter

    Ken Salter - 2015-07-21

    Dom, have you tried the test version attached to the post above yours?

     
  • Dom

    Dom - 2015-07-21

    Hi Ken, I hadn't tried that (just v0.0.0.14 from the download).

    Just did a quick test with the test version though and it looks a lot better so great job on that one - and apologies for not testing it first.

    One small caveat - it does an interesting job incrementing the counter on the files that have a number in the file extension e.g. .OUT_004, which v0.0.0.14 didn't do - it doesn't seem to like even numbers :-)

    Output below is the directory listing when I ran it a few times using the test case I specified in my post with -f to force a rotate, and I've attached the full output from the last run.

    TEST_L6.OUT.1
    TEST_L6.OUT.2
    TEST_L6.OUT.3
    TEST_L6.OUT.4
    TEST_L6.OUT_004.1
    TEST_L6.OUT_004.3
    TEST_L6.OUT_004.5
    TEST_L6.OUT_004.7
    TEST_L6.OUT_005.1
    TEST_L6.OUT_005.3
    TEST_L6.OUT_005.5
    TEST_L6.OUT_005.7

    Hope this helps, Dom

     
  • Ken Salter

    Ken Salter - 2015-07-21

    Okay thanks for the info...will take a look.

     
  • Ken Salter

    Ken Salter - 2015-07-21

    Interesting, I was unable to duplicate the odd numbering. It seems to be working correctly for me. Will continue to test...

     
  • Ken Salter

    Ken Salter - 2015-07-21

    Nevermind, I was able to duplicate it...will post a fix shortly

     
  • Ken Salter

    Ken Salter - 2015-07-21

    Okay Dom, I have attached 0.0.0.16 to this post. Give it a try.

     
  • Dom

    Dom - 2015-07-22

    Ken, that works perfectly! I also did a couple of other tests with different filenames e.g. 1.out, 4.out, 5.out plus 1.1.out, 4.4.out, etc, etc and all worked as expected.

    Great job and I really appreciate how quick you came back with updates.

    Thanks again, Dom

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.