Early review of std.logger

ilya-stromberg ilya-stromberg-2009 at yandex.ru
Tue Oct 15 07:48:00 PDT 2013


On Tuesday, 15 October 2013 at 14:25:55 UTC, Robert Schadek wrote:
> On 10/15/2013 04:17 PM, ilya-stromberg wrote:
>> On Tuesday, 15 October 2013 at 14:12:38 UTC, Sönke Ludwig 
>> wrote:
>>> But if it's available people _will_ use it in complex 
>>> contexts. Also
>>> if the writer of a 2<<8 loc library uses it and the library 
>>> is used
>>> by a large piece of software, that will also be affected. The 
>>> point
>>> is that it is unhygienic and requires non-trivial extra work 
>>> when
>>> using a logger in a multi-threaded environment. Some kind of 
>>> scoped
>>> stack of default log levels would get around this issue, but 
>>> that
>>> smells like over engineering.
>>
>> +1
>> I dislike syntax:
>> log.logLevel = LogLevel.warning;
>> log("This is a warning");
>>
>> Much better:
>> log.warning("This is a warning");
> You can also write log(LogLevel.warning, "This is a warning"); 
> And that
> also allows you to treat the LogLevel as a variable.
> log(myComputedLogLevel, "..."); Anyway, functions should be 
> verbs.

Yes, I know.
Idea: let all "as is" and just add `log.xxx("...");` functions. 
It looks like that solves all problems:
- we can log with configurable default log level (setup for all 
programm):
log("This is a warning");
- we can specify local log level (setup for class or function):
log(myComputedLogLevel, "...");
- and we can call log with specific log level:
log.warning("...");
or maybe
log.logWarning("..."); //yes, it is a verb


More information about the Digitalmars-d mailing list