• OpenLog thinks that dbInitiated = True when used in two agents run back-to-back on the web.

    By Peter LaComb 2 decades ago

    I've encountered an issue with OpenLog (1.5 BETA). Here's what I'm doing:



    In a web application, the submit button on a form runs an XMLHTTP request, and depending on the result, submits the document.



    Both the Agent run from the XMLHTTP request and the webquerysave agent (in the same database) use the OpenLogFunctions Script library.



    The agent run from the XMLHTTP Request completes OK (and writes to the log) The webquerysave runs, but fails to write to the log. I've traced this to the private dbInitiated variable being set to TRUE in the script library when webquerysave runs. I confirmed this by making it a public variable and setting it to false (in my webquerysave) before using any OpenLog funcions.



    I believe that this is because of the way HTTP handles script libraries, and I believe the fix is as follows (works for me, except that the logs from the second agent are recorded as if they came from the first - I'm open to suggestions that would better correct the issue).



    Note - My server is set to run web agents concurrently, and I have no idea if this has any impact on the issue (I haven't taken the time to test it yet)



    I've changed the GetLogDatabase to this:

    Function GetLogDatabase () As NotesDatabase

    '
    get a handle to the log database

    On Error Goto processError



    '
    if we've already tried doing this once, don't bother trying again;

    '
    either we were able to connect to the database and we've already

    '
    * got a handle to it, or we failed and we'd keep on failing

    If Not dbInitiated Then

    Call UseDefaultLogDb

    %REM

    Added by PTL 7/31/2007 because HTTP seems to initialize the script library once if used in two agents in a short period of time, yet somehow it invalidates the logDb object

    %END REM

    Elseif (logdb Is Nothing) Then

    Call UseDefaultLogDb

    'End PTL modification

    End If



    Set GetLogDatabase = logDb

    Exit Function



    processError:

    DebugPrint(StandardErrorMessage(Err, Erl, Error$, Getthreadinfo(1)))

    Resume Next



    End Function

    • Update (corrected 8/2/07)

      By Peter LaComb 2 decades ago

      I've found a way to correct the way the second agent is running… These changes to InitGlobalLogItem make sure that the second agent gets logged correctly.



      Sub InitGlobalLogItem ()

      '** initialize the global LogItem, if it hasn't been initialized already<br/>
      On Error Goto processError<br/>
      <br/>
      If (logDb Is Nothing) Then<br/>
      

      if not (globalLogItem is nothing) then

          Delete globalLogItem<br/>
      

      end if

      End If<br/>
      <br/>
      If (globalLogItem Is Nothing) Then<br/>
          Set globalLogItem = New LogItem<br/>
      End If<br/>
      <br/>
      Exit Sub<br/>
      <br/>
      

      processError:

      DebugPrint(StandardErrorMessage(Err, Erl, Error$, Getthreadinfo(1)))<br/>
      Resume Next<br/>
      <br/>
      

      End Sub



      *Minor correction on 8/2/07 because deleting GlobalLogItem when it is nothing is not a good idea.

      • Strange. Thanks for the fix!

        By Julian Robichaux 2 decades ago

        Strange behavior. I wouldn't have guessed that would happen.



        Thanks for the fix! I'll put it in the non-Beta version of 1.5. I need to push that out soon…


        • Julian
        • One last thing

          By Peter LaComb 2 decades ago

          I failed to mention that I had a bugger of a time tracing the source of this error because the CreateLogDoc function was printing when the db it was passes was nothing (so my users got a long list of "Log database was not defined. CreateLogDoc is exiting." on their pages.



          So, if I may suggest one more minor change:


          '******************************************************************************<br/>
          '** Create a log document in the specified database<br/>
          '******************************************************************************<br/>
          Function CreateLogDoc (db As NotesDatabase) As NotesDocument<br/>
              On Error Goto processError<br/>
              '** exit early if there is no database<br/>
              If (db Is Nothing) Then<br/>
                  Error 42, &quot;Log database was not defined. CreateLogDoc is exiting.&quot;<br/>
                  'Removed Print because this should really be an error.<br/>
                  'Print &quot;Log database was not defined. CreateLogDoc is exiting.&quot;<br/>
                  Exit Function<br/>
              End If
          
          • Good point

            By Julian Robichaux 2 decades ago

            Good point. Consider it done.