[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Issues with gb.logging Logger, cannot _free
[Thread Prev] | [Thread Next]
- Subject: Re: Issues with gb.logging Logger, cannot _free
- From: Bruce Steers <bsteers4@xxxxxxxxx>
- Date: Fri, 12 Apr 2024 10:14:42 +0100
- To: user@xxxxxxxxxxxxxxxxxxxxxx
I'm not sure about the problem you have killing the Logger object but it looks like you do not need to use Begin. Calling _new() of Logger.class makes a new ComplexLogger object. $cLogger = New ComplexLogger(sFormat, tmpHandler) And the _new() function of ComplexLogger.class already runs the Begin() method so using hLogger.Begin() runs it again causing the error. Strange it has a Begin function but no End Respects BruceS On Thu, 11 Apr 2024 at 21:19, T Lee Davidson <t.lee.davidson@xxxxxxxxx> wrote: > 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] > ---- > > >
Re: Issues with gb.logging Logger, cannot _free | T Lee Davidson <t.lee.davidson@xxxxxxxxx> |
Issues with gb.logging Logger, cannot _free | T Lee Davidson <t.lee.davidson@xxxxxxxxx> |