Jump to content

FileWriteLine behavior


Recommended Posts

Hello,

Maybe an unappropriate question, but i did not find any hint about that behavior of the function FileWriteLine.

You will find below the layer I use to manage my loging files.

The issue is that when I stop my script and look into logs I often see things like that :

10/03/2010 17:38:27 : LOG : Test 11

10/03/2010 17:39:58 : LOG : Success

10/03/2010 17:41:21 : LOG : Success

10/03/2010 17:42:54 : LOG : Success

10/03/2010 17:44:30 : LOG : Success

10/03/2010 17:46:03 : LOG : Success

10/03/2010 17:47:26 : LOG : Success

10/03/2010 17:49:13 : WARN : Failure

10/03/2010 17:51:04 : LOG : Success

10/03/

As you see, the last line seems truncated, which let me think that this is a flushing issue, I'm using Windows Seven 64bit.

Did I miss something, any hint to have complete logs ?

Best regards.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

#include-once
#Include <File.au3>
#Include <Date.au3>

Global $logFile = ""
Global $logFileHdl = ""

Func FileLog_SetLogFile($name)
    $logFile = $LogPath & "\" & $name
    $logFileHdl = FileOpen ($logFile,9) ; append mode
EndFunc

Func FileLog_UnsetLogFile()
    If $logFileHdl = "" Then
        fatalError("FileLog_UnsetLogFile : Undefined log file",False)
    EndIf
    FileClose($logFileHdl)
    $logFileHdl = ""
    $logFile = ""
EndFunc

Func FileLog_Append($line,$type = "LOG")
    If $logFileHdl = "" Then
        fatalError("FileLog_Append : Undefined log file",False)
    EndIf
    FileWriteLine($logFileHdl,_NowDate() & " " & _NowTime() & " : " & $type & " : " & $line)
EndFunc

Func FileLog_Delete()
    If $logFileHdl = "" Then
        fatalError("FileLog_Delete : Undefined log file",False)
    EndIf
    FileDelete($logFile)
    FileLog_UnsetLogFile()
EndFunc
Edited by trap16
Link to comment
Share on other sites

Please use code or autoit markups to insert code next time.

In short, yes you need to FileFlush if you need committment to disk. Not only the OS cache, but also the HD cache can delay disk writes. Recently someone found with his own logging system that the HD cache could delay for far more than one second. His system was crashing at the hardware level and that's why the tail of his files were truncated.

OTOH, I don't see why you should see truncated files in your case if your system/hardware reamains stable and functional. In my view, FileWriteLine does nothing special hat could prevent tail file writes.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thanks for for quick reply and the advice, I edited my post to add code marker, sorry for the inconvenience.

Maybe I'm missing something, but i do not see any function who can commit file buffer to disk. Can anyone give me a hint ?

Link to comment
Share on other sites

FileFlush() works well!

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Many Thanks,

Using FileFlush() lead to expected logger behavior.

And me bad ... was still not using autoit release which implement that function, that's why i didn't find this in the manual.

Edited by trap16
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...