On Thursday, 11 September 2014 at 22:10:01 UTC, Marco Leise wrote:
Am Thu, 11 Sep 2014 21:32:44 +0000
schrieb "Robert burner Schadek" <[email protected]>:

On Thursday, 11 September 2014 at 16:55:32 UTC, Marco Leise wrote: > 2. I noticed that as my logger implementation grew more > complex
>    and used functionality from other modules I wrote, that if
> these used logging as well I'd easily end up in a > recursive
>    logging situation.
>
>    Can recursion checks be added somewhere
>    before .writeLogMsg()?

I think I don't follow. Just to clear

foo() {
     log(); bar();
}

bar() {
     log(); foo();
}

Let me clarify. Here is some code from 2015:

void main()
{
        stdlog = new MyLogger();
        // This call may overflow the stack if
        // 'somethingBadHappened in someFunc():
        error("ERROR!!!");
}

class MyLogger : Logger
{
        override void writeLogMsg(ref LogEntry payload)
        {
                auto bla = someFunc();
                useBlaToLog(bla, payload.msg);
        }
}

// This is just some helper function unrelated to logging
// but it uses the stdlog functionality from Phobos itself
// as that is good practice in 2015.
auto someFunc()
{
        ...
        if (somethingBadHappened)
        {
                // Now I must not be used myself in a logger
                // implementation, or I overflow the stack!
                error("something bad in someFunc");
        }
        ...
}

well you could set the LogLevel to off and reset it afterwards


> 3. Exceptions and loggin don't mix.


hm, I think adding template function as requested by dicebot would solve that problem, as it would take line and friends as function parameters

How do you log errors that also throw exceptions ?

please elaborate. I think I misunderstand

Reply via email to