Jump to content

LogEvent UDF


FinalVersion
 Share

Recommended Posts

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
Link to comment
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?

Edited by nikink
Link to comment
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 ;)
Link to comment
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

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...