Sign in to follow this  
Followers 0
littleclown

Func makes log files

3 posts in this topic

#1 ·  Posted (edited)

Hello. This is my first function and thats why is only 9 lines long. I make it for me, but I believe your opinion and corrections make it better. If someone have another logfile system please show me :P. Here is the code with example:

$logfile=@ScriptDir & "\log-" & @YEAR & @MON & ".txt"

func _logs($event,$flag=1)
    if $flag=1 Then $flag = "INFO"
    if $flag=2 Then $flag = "WARNING"
    if $flag=3 Then $flag = "ERROR"
    $file = FileOpen($logfile,1)
    $timestamp = @MDAY & "." & @MON & "." & @YEAR &" "&@HOUR&":"&@MIN&":"&@SEC
    FileWriteLine($file,$timestamp & " - "& $flag & " - " & $event)
    FileClose($file)
EndFunc








$del = FileDelete("somefile.txt")
if $del Then 
_logs("Del somefile.txt") 
Else    
_logs("Cannot del somefile.txt!",2)
EndIf

I use this for my scripts coz I am not on the PC when the scrpts working, and I wont to know what happens with them in the next morning

Edited by littleclown

Share this post


Link to post
Share on other sites



You could also use the built in function '_FileWriteLog' and add a wrapper for your 'INFO', 'WARNING' and 'ERROR' info.

Good start. Take a look in 'File.au3' and see how '_FileWriteLog' is written.


“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Share this post


Link to post
Share on other sites

Hm. I see the _FileWriteLog and its pretty the same :P. The difference really is the event system. I will write log reader also :D.

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