Jump to content

AutoIt error logger (AUERLO) UDF


 Share

Recommended Posts

File- and stdout/-err (console) output of messages, regular- and COM Object errors, exit method and -code, etc.

  • Just call _AUERLO_Log() after to be logged functions (no parameters required if preceding function returns @error on failure). Or replace ConsoleWrite() (and SciTE trace lines) by _AUERLO_Log() for existing scripts.
  • _AUERLO_FileRead() and _AUERLO_View() to display error log file contents (or import as CSV file to Microsoft Excel for example).
  • Register custom functions to adjust date/time format and replace or add output functionality (no UDF source code modifications required).
  • Output to:
    • file
    • console (stdout and stderr)
    • non-blocking notification (Beep(), SoundPlay(), etc.)
    • prompt (GUI dialog; script-halting notification)
    • Microsoft Windows Event Log
    • custom (register function)

Download:

Remarks:

auerlo.au3 :

  • _AUERLO_Set()
  • _AUERLO_Log()
  • _AUERLO_LogAlt()
  • _AUERLO_LogWinAPI()
  • _AUERLO_LogEnv()
  • _AUERLO_Assert()
  • _AUERLO_FileClear()
  • _AUERLO_FileRead()
  • _AUERLO_View()

auerloConstants.au3 :

  • $AUERLO_LVL__ENUM - debug levels,
  • $AUERLO_OPT__ENUM - _AUERLO_Set() options,
  • $AUERLO_RET__ENUM - Return codes,
  • $AUERLO_ERR__ENUM - @error codes, and
  • $AUERLO_ATR__ENUM - error item attributes.

Usage explanation:

  • If @error signifies failure (implicit logging) :
    • _ArrayDisplay($sNotAnArray); Returns @error = 1.
      _AUERLO_Log()              ; Logs as $AUERLO_LVL_TRACE, $AUERLO_LVL_ERROR on @error, $AUERLO_LVL_DEBUG on @extended.
      If @error Then ...         ; _AUERLO_Log() transparently passes @error and @extended from _ArrayDisplay().
  • If return value signifies failure (explicit logging) :
  • If (return) value or expression result signifies failure (implicit logging):
    • Global $g_hFile = FileOpen('invalid path')
      _AUERLO_Assert(Not ($g_hFile = -1))        ; $AUERLO_LVL_DEBUG if True (success), $AUERLO_LVL_WARNING if False.
      _AUERLO_Assert(FileWrite($g_hFile, 'data')); Successfull return value (1) evaluates to True; failure (0) to False.
    • _AUERLO_Assert(IsArray($g_sNotAnArray))
  • Import error log file contents:
    • Global $g_aArray2D = _AUERLO_FileRead(); Reads from current error log file.
      _AUERLO_View($g_aArray2D)
  • Configuration ($AUERLO_OPT__ENUM in auerloConstants.au3 for description of all options) :
    • _AUERLO_Set($AUERLO_OPT_LOGFILE, False)   ; Disables output to error log file.
      _AUERLO_Set($AUERLO_OPT_LOGSTD,  True)    ; Enables output to stdout/stderr (console).
      _AUERLO_Set($AUERLO_OPT_FNCEXIT, Default) ; Registers default exit handler (no script exit logging without).
      _AUERLO_Set($AUERLO_OPT_FNCEXIT, Null)    ; Deregisters default exit handler.
      _AUERLO_Set($AUERLO_OPT_FNCCOM,  Default) ; Registers default COM Object error handler (no COM error logging without).
      _AUERLO_Set($AUERLO_OPT_FNCCOM,  Null)    ; Deregisters COM Object error handler.
      _AUERLO_Set($AUERLO_OPT_FNCCOM,  YourFunc); Registers custom COM Object error handler YourFunc().

 

Edited by user4157124
Link to comment
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
 Share

×
×
  • Create New...