Jump to content
Sign in to follow this  

Func makes log files

Recommended Posts

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)

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

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

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  

  • Create New...