Example code in std.logger.core doesn't even work
mw
m at g.c
Wed Jul 12 16:32:22 UTC 2023
On Wednesday, 12 July 2023 at 10:29:50 UTC, WebFreak001 wrote:
> On Wednesday, 12 July 2023 at 03:00:11 UTC, mw wrote:
>> On Monday, 13 March 2023 at 20:32:08 UTC, WebFreak001 wrote:
>>> On Monday, 13 March 2023 at 02:53:00 UTC, Yuxuan Shui wrote:
>>>> Example here:
>>>>
>>>> https://dlang.org/phobos/std_logger_core.html#.sharedLog
>>>>
>>>> Result:
>>>>
>>>> https://run.dlang.io/is/RMtF0I
>>>
>>> this changed in one of the most recent releases, but you can
>>> always expect breaking changes in an std.experimental module
>>
>> Can you please show the correct usage pattern of this
>> sharedLog, in the new release?
>
> what I do now in my code:
>
> ```d
> static if (__VERSION__ < 2101)
> sharedLog = new FileLogger(io.stderr);
> else
> sharedLog = (() @trusted => cast(shared) new
> FileLogger(io.stderr))();
> ```
>
> not a big fan of the changes and the fact that this got made
> std.logger instead of the previous API, but it works at least
1) Is this `cast` ugly?
2) if it's a regular file, is this still thread safe to use?
Without the `cast`, I got compiler error
https://run.dlang.io/is/h3S0eb
```
import std.stdio;
import std.algorithm;
import std.logger.core, std.logger.filelogger;
import std.range;
void main()
{
// sharedLog = new shared(FileLogger)("/dev/null");
static if (__VERSION__ < 2101)
sharedLog = new FileLogger(io.stderr);
else
sharedLog = (() @trusted => new shared(FileLogger)(stderr))();
}
```
onlineapp.d(13): Error: none of the overloads of `__ctor` are
callable using a `shared` object
/dlang/dmd/linux/bin64/../../src/phobos/std/logger/filelogger.d(40): Candidates are: `std.logger.filelogger.FileLogger.this(const(string) fn, const(LogLevel) lv = LogLevel.all)`
/dlang/dmd/linux/bin64/../../src/phobos/std/logger/filelogger.d(66): `std.logger.filelogger.FileLogger.this(const(string) fn, const(LogLevel) lv, Flag createFileNameFolder)`
/dlang/dmd/linux/bin64/../../src/phobos/std/logger/filelogger.d(105): `std.logger.filelogger.FileLogger.this(File file, const(LogLevel) lv = LogLevel.all)`
Sigh, D is so broken on such basic stuff.
More information about the Digitalmars-d
mailing list