Sign in to follow this  
Followers 0
FinalVersion

LogEvent UDF

4 posts in this topic

Either logs an "Event" or a "Error"

Put it in your;

C:\Program Files\AutoIt3\Include\

The Command:

LogEvent(0 or 1; 0 = event 1 = error, "Your Text Here")

Example.

;Example
#Include <LogEvent.au3> ;Will only work if you put it in your include directory
LogEvent(0, "This Is An Event")
Sleep(1000)
LogEvent(1, "This Is An Error" & @CRLF)
ExitoÝ÷ Ø    ÝêÞجjëh×6#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.13.13 (beta)
 Author:         Godly

 Script Function:
    Simple Logging Function
#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

Func LogEvent($Code, $String)
    $LogFile = FileOpen(@ScriptDir & "\Logs.txt", 1)
    Select
    Case $Code = 0
        FileWriteLine($LogFile, "<Event>" & " " & @Hour & ":" & @Min & ":" & @Sec & " | " & $String)
    Case $Code = 1
        FileWriteLine($LogFile, "<Error>" & " " & @Hour & ":" & @Min & ":" & @Sec & " | " & $String)
    EndSelect
    FileClose($LogFile)
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Nice and simple. Good work! ^_^

But it might be a bit slow due to all the File Opening, writing and Closing though. Perhaps append to a string and perform one Open, write and Close at the end?

EDIT: And having a way to have a unique name for the log file, to prevent multiple scripts from clashing and overwriting?

Edited by nikink

Share this post


Link to post
Share on other sites

Nice and simple. Good work! ^_^

But it might be a bit slow due to all the File Opening, writing and Closing though. Perhaps append to a string and perform one Open, write and Close at the end?

EDIT: And having a way to have a unique name for the log file, to prevent multiple scripts from clashing and overwriting?

Feel free to go ahead and edit it, just post what you end up with ;)

Share this post


Link to post
Share on other sites

Nice effort Godly, however you might want to have a look at this...

Func LogEvent($String, $Code = 1)
    Local $eType = "<Error>", $LogFile = FileOpen(@ScriptDir & "\Logs.txt", 1)
    If $Code <> 1 Then $eType = "<Event>"
    FileWriteLine($LogFile, $eType & " " & @Hour & ":" & @Min & ":" & @Sec & " | " & $String)
    FileClose($LogFile)
EndFunc

#1

It is a lot of unnecessary work to use "Include" for one Function.

#2

The "String" should be first as the "Type" can be 1 constantly with the second parameter changed only when needed.

#3

See _FileWriteLog()

8)


NEWHeader1.png

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