MathewThomas

Write Output to a Text File for Logging

9 posts in this topic

Hi

I have created a test autoit Script and am running it through SCiTe. THe script executes fine but I want to capture logs so that I can track it incase the automation fails or has any errors. I can write custom messages or text to a file but I want to  capture output that appearrs in the console. I have attached a screenshot of the logs I intend to capture.

I want to log messages that appear in the output window over here to a text file. 

 

test.png

Share this post


Link to post
Share on other sites



@MathewThomas our forum has a pretty good search feature, something worth trying before you post. You can also look through the help file for suggestions. _FileWriteLog, for example, can write out to a log file for you. You could also use the _EventLog__* functions to use the Windows Event logs for your application.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

HI @JLogan3o13 I did search the forum and could not find a solution to what I am looking to do. THe FWritelog function just writes text that the user specifies to a log file. I am trying to find a way to write the messages that appear in the output window to a file.

 

Share this post


Link to post
Share on other sites

So rather than a picture (pictures are for Facebook) how about posting some code that shows what you're trying to do. Do you mean you're trying to automatically capture STDOut, or you want to capture everything in the console, time of completion, run time, etc?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Yes I need to capture everything that appears in the console. Sometimes there are errors too which pop there which I need to write to a file. The picture above shows the section of output I am referring to.

 

Share this post


Link to post
Share on other sites

I seem to recall LazyCat doing something like this years ago; you might search the forum for DConsole. The only other way I could think of is to try a ControlGetText on the Console pane, but still think it is not a great idea. You should code in such a way you're catching errors on purpose, not just grabbing everything.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

I use:
 

#include <File.au3>
Func _WriteErrorLog($ErrorMessage)
    Local $Logfile = @WorkingDir & "\" & @ScriptName & ".log"
    Local $errorFile = $Logfile
    Local $LogTime = @HOUR & ":" & @MIN & ":" & @SEC
    Local $hFileOpen = FileOpen($errorFile, 9)
    FileWriteLine($hFileOpen, $LogTime & " " & $ErrorMessage & @CRLF)
    FileClose($hFileOpen)
EndFunc   ;==>WriteErrorLog

Cheers, Starf0x

Share this post


Link to post
Share on other sites

@Starf0x, a couple of things:

  • Your script doesn't do what the OP is asking (capture the entirety of the SciTE output pane)
  • Why do you declare a variable for the log file ($Logfile), only to declare it all over again in the very next line ($errorfile)?
  • Your entire function could be boiled down to a single line (two if you want to declare the filename in a variable) and without the need for the include:
_WriteErrorLog("Boy this is less code")

Func _WriteErrorLog($ErrorMessage)
    FileWriteLine(@ScriptDir & "\" & @ScriptName & ".log", @HOUR & ":" & @MIN & ":" & @SEC & ": " & $ErrorMessage)
EndFunc   ;==>WriteErrorLog

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Who said I was perfect? ^_^

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