Jump to content
Sign in to follow this  
criticalmass

Output Log for functions being ran

Recommended Posts

I want to make a function for my program i made. its a diagnostic tool that does pretty neat stuff. but i wanna beable to make a output fucntion that records everything to a text doc.

So if they run "Apache Restart" or "Task Manager"

I want it to show in the log

Apache Restart "Date" "Month" "Year" "Time"

Task Manager "Date" "Month" "Year" "Time"

how would i go about doing something like this?

Share this post


Link to post
Share on other sites

I dont understand how this should work. I am sorry I am still learning

Here is a example of what I need

; Restart Apache
 $rsapache = GUICtrlCreateMenuItem("Restart Apache", $hBtnArrowContext)

and the file that executes the Restart Apache is.

Case $rsapache 
        RunCommandLine("net stop Apache2.2")    
                RunCommandLine("net start Apache2.2")

I need to have that go to a log file. I also have:

Restart SQL

Restart Services

and a few others but I need it to go into just a log doesnt have to be the same log but it can be *.log

If anyone can help this would be amazing. I need it to be logged every time someone clicks on a button.

Edited by criticalmass

Share this post


Link to post
Share on other sites

PsaltyDS gave you a good suggestion - if you would have searched the help file you would have found this:

_FileWriteLog

--------------------------------------------------------------------------------

Writes current date,time and the specified text to a log file.

#Include <File.au3>

_FileWriteLog($sLogPath, $sLogMsg [, $iFlag = -1])

Parameters

$sLogPath Path and filename of the file to be written to

$sLogMsg Message to be written to the log file

$iFlag [optional] Flag that defines if $sLogMsg will be written to the end of file, or to the begining.

If $iFlag = -1 (default) $sLogMsg will be written to the end of file.

If $iFlag <> -1 $sLogMsg will be written to begining of file.

Return Value

Success: 1

Failure: 0 and set @error

@Error: 1 = Error opening specified file

2 = File could not be written to

Remarks

None

Example

#include <file.au3>

;

_FileWriteLog(@ScriptDir & "\my.log","Text 1")

;

_FileWriteLog(@ScriptDir & "\my.log","Text 2")

That's what you need to use; you can write to any file once you specify the correct path.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Wow - did you try to think a little about this? Have you tried to put together some code?

This is as simple as this:

#include <file.au3>
;since it is not specified if _FileWriteLog will create a new file - be sure to create the log files first
Global $myLog_1 = @ScriptDir&"\Apache.log"
Global $myLog_2 = @ScriptDir&"\Other.log"

Case $rsapache 
        RunCommandLine("net stop Apache2.2") 
        _FileWriteLog($myLog_1,"Stopping Apache")       
        RunCommandLine("net start Apache2.2")
        _FileWriteLog($myLog_1,"Starting Apache")   
        RunCommandLine("run other crap")
        _FileWriteLog($myLog_2,"Some other crap logged here")

... DOH ... so simple ...

Stop being lazy.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

If the Apache2.2 service quotes the date/time with its own output to the console, then all you have to do is capture that. This can be done by redirection ">>" on the shell command line:

$sLogFile = 'C:\Temp\MyLogFile.log'

; ...

    Case $rsapache 
        RunCommandLine('net stop Apache2.2 >> "' & $sLogFile & '"')    
        RunCommandLine('net start Apache2.2 >> "' & $sLogFile & '"')

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...