Sign in to follow this  
Followers 0
longxx

question--how to make log system? (such as .txt file)

10 posts in this topic

My current script runs overnight, but I would like to have some sort of log system

I think making it into .TXT file would be good idea.

is there any function does such things? such as by keep adding/saving stuff into a .txt file?

thanks!

Share this post


Link to post
Share on other sites



FileWriteLine("C:\log.txt",@YEAR)
for an example


[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites

My current script runs overnight, but I would like to have some sort of log system

I think making it into .TXT file would be good idea.

is there any function does such things? such as by keep adding/saving stuff into a .txt file?

thanks!

I prefer the _FileWriteLog() function in the File.au3 UDF. It automatically date/time stamps entries:
#include <File.au3>

$sLogFile = "C:\Temp\Test.log"
_FileWriteLog($sLogFile, "Script started.")

MsgBox(32, "Question", "Done yet?")
_FileWriteLog($sLogFile, "User is done, displaying log file.")

Run("notepad.exe " & $sLogFile)

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

@ PlastyDs

can we write the whole log of a program without adding for every line to write the log.


sorry for my spelling mistakes. its due to be fast !!!

Share this post


Link to post
Share on other sites

@ PlastyDs

can we write the whole log of a program without adding for every line to write the log.

I don't know what you mean. Where does "the whole log of a program" come from?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

i want to create the whole log of my program.

can you give me a example?


sorry for my spelling mistakes. its due to be fast !!!

Share this post


Link to post
Share on other sites

What's whole log of my program ?

can you describe it ?


[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

you could also use debugview and log all there

http://technet.microsoft.com/en-us/sysinte...s/bb896647.aspx

; view with debug view

;

;

; credits go to

; Karsten Violka (kav@ctmagazin.de), Stefan Porteck (spo@ctmagazin.de)

;

Func _DebugPrint($msg, $error = @error, $extended = @extended, $ScriptLineNumber = @ScriptLineNumber)

; view with debug view

;

Local $out = $msg & ", Line:" & $ScriptLineNumber & ", Error: " & $error & " " & $extended

;Output to application attaching a console to the script engine

ConsoleWrite($out & @CRLF)

;Output to debugger (dbgview.exe)

DllCall("kernel32.dll", "none", "OutputDebugString", "str", $out)

EndFunc ;==>_DebugPrint

Edited by nobbe

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I prefer the _FileWriteLog() function in the File.au3 UDF. It automatically date/time stamps entries:

#include <File.au3>

$sLogFile = "C:\Temp\Test.log"
_FileWriteLog($sLogFile, "Script started.")

MsgBox(32, "Question", "Done yet?")
_FileWriteLog($sLogFile, "User is done, displaying log file.")

Run("notepad.exe " & $sLogFile)

:)

hi PsaltyDS, your command involves extra #include and more lines of codes...

can you tell me why would it better than previously suggested "FileWriteLine("C:\log.txt",@YEAR)"?

thanks.

EDIT:

I found this from file.au3

Func _FileWriteLog($sLogPath, $sLogMsg, $iFlag = -1)
    ;==============================================
    ; Local Constant/Variable Declaration Section
    ;==============================================
    Local $sDateNow, $sTimeNow, $sMsg, $iWriteFile, $hOpenFile, $iOpenMode = 1

    $sDateNow = @YEAR & "-" & @MON & "-" & @MDAY
    $sTimeNow = @HOUR & ":" & @MIN & ":" & @SEC
    $sMsg = $sDateNow & " " & $sTimeNow & " : " & $sLogMsg

    If $iFlag <> -1 Then
        $sMsg &= @CRLF & FileRead($sLogPath)
        $iOpenMode = 2
    EndIf

    $hOpenFile = FileOpen($sLogPath, $iOpenMode)
    If $hOpenFile = -1 Then Return SetError(1, 0, 0)

    $iWriteFile = FileWriteLine($hOpenFile, $sMsg)
    If $iWriteFile = -1 Then Return SetError(2, 0, 0)

    Return FileClose($hOpenFile)
EndFunc   ;==>_FileWriteLogoÝ÷ ÚÊjÈjYr*ÞZ¸­xº ë-i×lu«^þئz)ß®í¡ûazg¬±¨Ýý²X¤y©ÞƧ²*'¡ñb­å«×w­êeiǶ°^)^Z¸­xº Â+a¶¬¢w¥w¨}ÊxÞÞvØ^~V !Ú'ßÛlyëaz"Úج¶¬×jëh×6  FileWriteLine("C:\log.txt", @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & "TEST")

thanks.

Edited by longxx

Share this post


Link to post
Share on other sites

hi PsaltyDS, your command involves extra #include and more lines of codes...

can you tell me why would it better than previously suggested "FileWriteLine("C:\log.txt",@YEAR)"?

; ...

so basically _FireWriteLog just adds date/time infront of the message ,

it's like an expansion of FireWriteLine

I replaced the whole _FileWriteLog with this one line of code, I removed the flag, I don't see the point of it,

is this good idea?

FileWriteLine("C:\log.txt", @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & "TEST")
If that's all you need, go with it! But think about how many calls you make like that...

...let's say there's 100 lines like that in your script...

...there's 83 characters in that line, so there's 8300 characters in your code for this...

...but this line: _FileWriteLog($sFile, "TEST") is only 27 characters, for 2700 total + about 750 for the function declaration (extracted from the UDF file) makes about 3450.

The math says after about 15 to 20 lines of this, your function uses more typing/characters than the function. You can complain about the size of the entire UDF, but file size differences of a few KB don't mean anything any more, like they did when we had to tweak EMM386.SYS and LOADHI parameters to squeak out a few KB more available memory from DOS/Windows 3.11! And as for coding/reading/debugging the whole thing (including the subject function) it's really only 19 characters: "#include <File.au3>"

So using a function for anything you repeat more than a few times makes sense. If your scripts are still very short and simple then your way might make more sense, but I would encourage you to start thinking about the habits you want to get into now that will stick with you when you work on bigger, more complicated projects.

The _FileWriteLog() method puts in more information than your function (@YEAR and @SEC), and is easier to type while coding, and easier to read while debugging. In addition, you should NEVER hard code things like file paths ("C:\log.txt") in your functions because if you decide to change it to "C:\Logs\log.txt" you now have to find and change every instance vice fixing one Global variable at the top of your script: Global $sLogFile = "C:\Logs\log.txt"

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
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
Sign in to follow this  
Followers 0