Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/06/2014 in all areas

  1. zorphnog

    log4a - A logging UDF

    I routinely need to log information for my scripts. In the past, I've usually just created functions in each script to write to a log file. I also use ConsoleWrite in conjunction with SciTE a lot when I'm trying to debug scripts. After using some logging libraries for other languages (namely NLog (C#) and Java (log4j)) I decided to write a logging UDF for AutoIt. I decided to base it loosely upon the log4j and NLog libaries. I say loosely because this one is not nearly as feature rich as either one of those, but I think it still provides a nice logging interface. What can it do? Output types: Console, File, or Both. Additionally, you can configure the logger to output differently based on whether the script is compiled or not. This way you can output to the console (SciTE) while you're writing a script, and output to a log file when you've compile the script. Log levels: While I don't think it's really necessary to have this many log levels, these are the levels in ascending order of severity: Trace Debug Info Warn Error Fatal Log Filtering: The log can be enabled and disabled. There are also minimum and maximum log levels that can be configured to only show a range of log levels (i.e. a minimum level of warn would not log messages for trace, debug, or info). These filter levels can be overridden when logging a message if the need be. Error Stream: Logging can be configured to write to the stderr (i.e. ConsoleWriteError). When enabled, any log messages at the error level and above will be written to the error stream. Message Format Macros: The logging message format can be customized to your liking using the following macros: ${date} = Long date (i.e. MM/DD/YYYY HH:MM:SS) ${host} = Hostname of local machine ${level} = The current log level ${message} = The log message ${newline} = Insert a newline ${shortdate} = Short date (i.e. MM/DD/YYYY) Available Functions: Configuration Functions _log4a_SetCompiledOutput - Sets the logging output type for the compiled version of the script (Default: $LOG4A_OUTPUT_FILE) _log4a_SetEnable - Enables or disables logging messages (Default: Disabled) _log4a_SetErrorStream - Enables or disables logging of the standard error stream (Default: Enabled) _log4a_SetFormat - Configures the format of logging messages (Default: "${date} ${level} ${message}") _log4a_SetLogFile - Sets the path of the log file (Default: "<ScriptFullPath>.log") _log4a_SetMaxLevel - Configures the maximum log level to process messages (Default: $LOG4A_LEVEL_FATAL) _log4a_SetMinLevel - Configures the minimum log level to process messages (Default: $LOG4A_LEVEL_TRACE) _log4a_SetOutput - Sets the logging output type for the non-compiled version of the script (Default: $LOG4A_OUTPUT_CONSOLE) Logging Functions _log4a_Debug - Logs a message at the debug level _log4a_Error - Logs a message at the error level _log4a_Fatal - Logs a message at the fatal level _log4a_Info - Logs a message at the info level _log4a_Message - Logs a message to the configured outputs _log4a_Trace - Logs a message at the trace level _log4a_Warn - Logs a message at the warn level See the source file for full documentation of available functions. A quick example script: #include "log4a.au3" ; Enable logging and don't write to stderr _log4a_SetEnable() _log4a_SetErrorStream(False) log_messages() ; Write to stderr, set min level to warn, customize message format _log4a_SetErrorStream() _log4a_SetMinLevel($LOG4A_LEVEL_INFO) If @compiled Then _log4a_SetMinLevel($LOG4A_LEVEL_WARN) ; Change the min level if the script is compiled _log4a_SetFormat("${shortdate} | ${host} | ${level} | ${message}") log_messages() ; Disable logging (except for those that override) _log4a_SetEnable(False) log_messages() Func log_messages() _log4a_Trace("A TRACE message", True) ; overrides filters _log4a_Debug("A DEBUG message") _log4a_Info("A INFO message") _log4a_Warn("A WARN message") _log4a_Error("A ERROR message", True) ; overrides filters _log4a_Fatal("A FATAL message") EndFunc Without further adieu, the UDF: log4a.au3
    1 point
  2. JohnOne

    Upload File to FTP

    _FTP_FilePut ( $hConn, @DesktopDir & "1.txt" , "1.txt")
    1 point
  3. Hi, In your first For loop : If FileExists Then DeleteFile << The file exists and is deleted ElseIf Not FileExists Then FileCreate << The file does NOT exist and is created EndIf The code cannot pass from an If to another one, so either the file exists or it does not. #include <File.au3> #include <Constants.au3> Local $setFiles[13] = [ _ "idsdk.dll", _ "sdk.dll", _ "ProcSafe.exe", _ "Safe.dll", _ "BHOEx.dll", _ "CServer.dll", _ "vDiskBus.inf", _ "vDiskBus.sys", _ "nti.exe", _ "GdiPlus.dll", _ "data\ClientBrand.ini", _ "data\GameSearchCfg.ini", _ "processSafe\ProcessSafe.ini"] For $i = 0 To UBound($setFiles) - 1 If FileExists(@ScriptDir & "\" & $setFiles[$i]) Then FileDelete(@ScriptDir & "\" & $setFiles[$i]) EndIf ;the file is necessarily deleted _FileCreate(@ScriptDir & "\" & $setFiles[$i]) ;Sleep(200) ;Why?? FileSetAttrib(@ScriptDir & "\" & $setFiles[$i], "+RSH") Next Local $SetACL_Set = "SetACL -on" Local $copy_permissions = '-ot file -actn setprot -op "dacl:p_c;sacl:p_c"' Local $remove_permissions = '-ot file -actn clear -clr "dacl,sacl"' Local $iRead_ex = '-ot file -actn ace -ace "n:Everyone;p:read_ex"' For $i = 0 To UBound($setFiles) - 1 If FileExists(@ScriptDir & "\" & $setFiles[$i]) Then ;this may be useless as the file is created before RunWait(@ComSpec & " /c " & $SetACL_Set & " " & @ScriptDir & "\" & $setFiles[$i] & " " & $copy_permissions, "", @SW_HIDE) RunWait(@ComSpec & " /c " & $SetACL_Set & " " & @ScriptDir & "\" & $setFiles[$i] & " " & $remove_permissions, "", @SW_HIDE) RunWait(@ComSpec & " /c " & $SetACL_Set & " " & @ScriptDir & "\" & $setFiles[$i] & " " & $iRead_ex, "", @SW_HIDE) EndIf Next MsgBox($MB_SYSTEMMODAL, "Waiting......", "Waiting......", 3) Br, FireFox.
    1 point
  4. Melba23

    0.0999999999999996

    zeropointone, It is not a bug - at least not in Autoit as it affects all computers. Google "floating point arithmetic" and you will learn more than you wish or need to know. M23 Edit: Welcome to the forum, by the way.
    1 point
  5. TCP (Transmission Control Protocol) shud be TCP regardless of what program you use on other end. one app to comunicate with another shud not have any problems if you know how to send with one language and how to recive with another.
    1 point
  6. tcp is not patented by AutoIt. why would that NOT be possible?
    1 point
  7. Oh, you need to study the SI prefixes
    1 point
  8. Having Problems running this script. Here is the code: $server = 'ftp.host.com' $username = 'host\username' $pass = 'mypassword' $Open = _FTPOpen('MyFTP Control') $Conn = _FTPConnect($Open, $server, $username, $pass) $Ftpp = _FtpGetFile($Conn, '/Update/contact.htm', 'c:\contact.htm') $Ftpc = _FTPClose($Open) When I run this the error message is $Open =_FTPOpen('MyFTP Control') $Open =^ERROR Error: Unknown Function Name.... Newbie missing something simple..... Cheers Mike
    1 point
×
×
  • Create New...