[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Issues with gb.logging Logger, cannot _free


After a Logger object has been created and Logger.Begin() fails, the object cannot be freed nor can it be re-created.

[code]
Public Sub Main()

  Dim hLogger As Logger

  hLogger = New Logger(Logger.Debug, "[$(now) $(message)]") ' sOutput argument intentionally omitted
  Try hLogger.Begin
  If Error Then
    Debug TypeOf(hLogger), IsNull(hLogger), Object.IsValid(hLogger) ' Main.Main.10: 16  False  True
    If Not IsNull(hLogger) Then
      hLogger = Null ' This causes error: "Uninitialized or already closed handler!"
      ' hLogger = New Logger ' This also causes error: "Uninitialized or already closed handler!"
    Endif
    Error.Raise("Cannot initialize logging: " & Error.Text)
    Return
  Endif

End
[/code]

I suspect the "Uninitialized or already closed handler!" may be caused by the Logger class' _free() method which contains only, "If $cLogger Then $cLogger.Close()". I would call Logger.Close() directly instead of setting the Logger object to Null, but the class exposes no such method.

There also appears to be a logical design flaw in the class. Logger._new() accepts three arguments all of which, collectively, are Optional including sOutput which is for the output path. Yet, the Logger.Output property is read-only which means it cannot be set after the object is created. So, sOutput should not be Optional in Logger._new() or Logger.Output should be read/write.


Am I trying to free the resource incorrectly?

--
Lee

--- Gambas User List Netiquette [https://gambaswiki.org/wiki/doc/netiquette] ----
--- Gambas User List Archive [https://lists.gambas-basic.org/archive/user] ----


Follow-Ups:
Re: Issues with gb.logging Logger, cannot _freeNeil Darlow <neil@xxxxxxxxxxxx>
Re: Issues with gb.logging Logger, cannot _freeBruce Steers <bsteers4@xxxxxxxxx>
Re: Issues with gb.logging Logger, cannot _freeBB <adamnt42@xxxxxxxxx>
Re: Issues with gb.logging Logger, cannot _freeBB <adamnt42@xxxxxxxxx>