Sign in to follow this  
Followers 0
jdelaney

sovled-ConsoleWrite abnormality (due to consolewriteerror)

1 post in this topic

#1 ·  Posted (edited)

I have a basic logging function, which when not compiled, also ouputs to scite via consolewrite (simplified the reproduction in the script below)

When the log is called with a failed step, I grab a screen shot of the active window, which somehow seems to cause scite to not 'get' the consolewrite until after the subsequent call to the same function...when I put in hard coded sleeps after the consolewrite, it works fine, but shouldn't a single threaded process not have this as a possibliity?

#include <ScreenCapture.au3>
$giSubFunctionCounter = 1
$giMaxLogLevel = 2
$gbDisplayMessage = False
$gbDisplayInformMessage = False
$gbTerminateOnFailure = False
$giLogState_Fail = 0
$giLogState_Pass = 1
$giLogState_Info = 2

Var_SetLogAndActOnState3(0,1,"test","details")
Var_SetLogAndActOnState3(1,1,"test","details")

Func Var_SetLogAndActOnState3($iCallersStateToLog, $iCallersLogLevel, $sCallersLogCategoryName, $sCallersLogDetails, $bCallersShowUser=Default, $CallersbTerminateOnFailure=Default, $bCallersSaveScreenShotOnFailure=Default, $sCallersScriptAndDir=Default, $sCallersScriptLine=Default) ; Logging

    If $iCallersLogLevel <= $giMaxLogLevel Then
        If $bCallersShowUser=Default Then
            $bCallersShowUser=$gbDisplayMessage
            If $iCallersStateToLog=$giLogState_Info Then $bCallersShowUser=$gbDisplayInformMessage
        EndIf
        If $CallersbTerminateOnFailure=Default Then $CallersbTerminateOnFailure=$gbTerminateOnFailure
        If $bCallersSaveScreenShotOnFailure=Default Then $bCallersSaveScreenShotOnFailure=True
        If $sCallersScriptAndDir=Default Then $sCallersScriptAndDir=""
        If $sCallersScriptLine=Default Then $sCallersScriptLine=""

        Local $sLogLine, $sPrefix, $sIndentsSpacing, $iSpaces, $iYear=StringRight(@YEAR, 2), $sDateTime = @MON & "/" & @MDAY & "/" & $iYear & " " & @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC

        Switch $iCallersStateToLog
            Case $giLogState_Fail
                $sPrefix = " A E - "
            Case $giLogState_Pass
                $sPrefix = " A W - "
            Case $giLogState_Info
                $sPrefix = " A I - "
            Case Else
                $sPrefix = " A E - "
        EndSwitch

        ; Open file for edits
        $sCallersLogCategoryName &= ": "

        ; Add a space for each $giSubFunctionCounter prior
        $sIndentsSpacing = StringFormat("%" & $giSubFunctionCounter & "s", "")

        $sCallersLogCategoryName = $sIndentsSpacing & $sCallersLogCategoryName
        If $giSubFunctionCounter Then
            $iSpaces = 37
        Else
            $iSpaces = 36
        EndIf
        ; Add a fixed amount of " " to end of string until len at least = $iSpaces (already appending 2 characters above)...improve readability of log file
        $sCallersLogCategoryName = StringFormat("%-" & $iSpaces & "s", $sCallersLogCategoryName)

        If $bCallersSaveScreenShotOnFailure And $iCallersStateToLog=$giLogState_Fail Then
            Global $sScreenShotImgFile = @DesktopDir & "\" & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & @MSEC & ".jpg"
            $hwnd = WinGetHandle("[ACTIVE]")
            If IsHWnd($hwnd) Then
                $aWinPos = WinGetPos($hwnd)
                If IsArray($aWinPos) Then
                    If Int($aWinPos[2]) > 100 And Int($aWinPos[3]) > 100 Then
                        _ScreenCapture_Capture($sScreenShotImgFile, Int($aWinPos[0]), Int($aWinPos[1]), Int($aWinPos[0]) + Int($aWinPos[2]), Int($aWinPos[1]) + Int($aWinPos[3]))
                        $sCallersLogDetails = $sCallersLogDetails & "..Screenshot saved=[" & $sScreenShotImgFile & "]."
                    Else
                        $sCallersLogDetails = $sCallersLogDetails & "..Unable to save Screenshot=[ActiveWindowTooSmall]."
                    EndIf
                Else
                    $sCallersLogDetails = $sCallersLogDetails & "..Unable to save Screenshot=[FailedToGetWinPos]."
                EndIf
            Else
                $sCallersLogDetails = $sCallersLogDetails & "..Unable to save Screenshot=[Can'tGetActiveWindowHandle]."
            EndIf
        EndIf

        $sLogLine=$sDateTime & $sPrefix & $sCallersLogCategoryName & $sCallersLogDetails

        ; Conditionally consolewrite
        If Not @Compiled Then
            If $iCallersStateToLog Then
                ConsoleWrite($sLogLine & @CRLF)
            Else
                ConsoleWriteError($sLogLine & @CRLF)
            EndIf
            If StringLen($sCallersScriptAndDir) > 0 Then
                If StringLen($sCallersScriptLine) > 0 Then
                    $sCallersScriptLine = "(" & $sCallersScriptLine & ",1)  : Navigate to script/line"
                Else
                    $sCallersScriptLine = "(1,1)  : Navigate to script/line"
                EndIf
                ConsoleWrite($sCallersScriptAndDir & $sCallersScriptLine & @CRLF)
            EndIf
            If $bCallersSaveScreenShotOnFailure And $iCallersStateToLog=$giLogState_Fail Then
;~              Sleep(1000)
            Else
;~              Sleep(10)
            EndIf
        EndIf
    EndIf
EndFunc   ;==>Var_SetLogAndActOnState

output (notice the time stamp of the first consolewrite is after the second):

08/01/13 14:28:26.177 A W -  test:                               details
08/01/13 14:28:26.038 A E -  test:                               details..Screenshot saved=[C:UsersuserDesktop20130801142826039.jpg].

edit...added a lot more calls, just to see the length of time diff:

Var_SetLogAndActOnState3(1,1,"somelongfunctionname","START")
Var_SetLogAndActOnState3(0,1,"somelongfunctionname","SCREENSHOT!")
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)
$giSubFunctionCounter += 1
Var_SetLogAndActOnState3(1,1,"somelongfunctionname","details" & $giSubFunctionCounter)

output:

08/01/13 14:52:03.964 A W - somelongfunctionname:               START
08/01/13 14:52:04.079 A W -  somelongfunctionname:               details1
08/01/13 14:52:04.079 A W -   somelongfunctionname:              details2
08/01/13 14:52:04.079 A W -    somelongfunctionname:             details3
08/01/13 14:52:04.080 A W -     somelongfunctionname:            details4
08/01/13 14:52:04.080 A W -      somelongfunctionname:           details5
08/01/13 14:52:04.080 A W -       somelongfunctionname:          details6
08/01/13 14:52:04.080 A W -        somelongfunctionname:         details7
08/01/13 14:52:04.080 A W -         somelongfunctionname:        details8
08/01/13 14:52:04.081 A W -          somelongfunctionname:       details9
08/01/13 14:52:04.081 A W -           somelongfunctionname:      details10
08/01/13 14:52:04.081 A W -            somelongfunctionname:     details11
08/01/13 14:52:04.081 A W -             somelongfunctionname:    details12
08/01/13 14:52:04.082 A W -              somelongfunctionname:   details13
08/01/13 14:52:04.082 A W -               somelongfunctionname:  details14
08/01/13 14:52:04.082 A W -                somelongfunctionname: details15
08/01/13 14:52:03.964 A E - somelongfunctionname:               SCREENSHOT!..Screenshot saved=[C:\Users\user\Desktop\20130801145203965.jpg].
08/01/13 14:52:04.082 A W -                 somelongfunctionname: details16
08/01/13 14:52:04.083 A W -                  somelongfunctionname: details17
08/01/13 14:52:04.083 A W -                   somelongfunctionname: details18
08/01/13 14:52:04.083 A W -                    somelongfunctionname: details19
08/01/13 14:52:04.083 A W -                     somelongfunctionname: details20
08/01/13 14:52:04.084 A W -                      somelongfunctionname: details21
08/01/13 14:52:04.084 A W -                       somelongfunctionname: details22
08/01/13 14:52:04.084 A W -                        somelongfunctionname: details23
08/01/13 14:52:04.084 A W -                         somelongfunctionname: details24
08/01/13 14:52:04.085 A W -                         test:        details

Got it...it's the difference between consolewrite and consolewriteerror...since I'm not compiling as a conole exe, made all consolerwrites...solved...but not sure why the two would be so different in output

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

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  
Followers 0