std.experimental.logger: practical observations

Robert burner Schadek via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 12 02:46:18 PDT 2014


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" <rburners at gmail.com>:
>
>> 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



More information about the Digitalmars-d mailing list