Bug 23487 – std.experimental.logger assigning FileLogger to sharedLog no longer works
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2022-11-15T15:14:31Z
Last change time
2024-11-17T01:03:56Z
Keywords
pull
Assigned to
No Owner
Creator
Jan Jurzitza
Comments
Comment #0 by d.bugs — 2022-11-15T15:14:31Z
the example code that's given in the logger documentation no longer works:
```d
sharedLog = new FileLogger("New_Default_Log_File.log");
```
(from https://dlang.org/phobos/std_experimental_logger.html)
Error:
serverbase/source/served/serverbase.d(595,2): Error: none of the overloads of `sharedLog` are callable using argument types `(FileLogger)`
/opt/hostedtoolcache/dc/dmd-2.101.0/x64/dmd2/linux/bin64/../../src/phobos/std/logger/core.d(1456,26): Candidates are: `std.logger.core.sharedLog()`
/opt/hostedtoolcache/dc/dmd-2.101.0/x64/dmd2/linux/bin64/../../src/phobos/std/logger/core.d(1471,16): `std.logger.core.sharedLog(shared(Logger) logger)`
this has only started happening with DMD 2.101.0 now
Trying to use `new shared FileLogger()` also doesn't work, so I'm not sure how to fix this issue from user code, as it looks like assigning a shared Logger is the more correct thing to do here.
The 2.108.1 are live, and the example at that URL still doesn't work.
This seems to do the trick:
sharedLog = cast(shared(Logger)) new FileLogger("foo.log");
Is this now considered the correct way to do it?
It would be nice if awkward casts like this were not imposed on the user.
Comment #3 by Bastiaan — 2024-07-05T15:49:08Z
There is a PR to adjust the documentation for this (https://github.com/dlang/phobos/pull/8995) but, as Nicholas Wilson points out, the correct syntax would be
```d
sharedLog = new shared(FileLogger)(yourFile);
```
This does not work since there is currently no shared constructor. I have tried to implement one in https://github.com/dlang/phobos/pull/8996, but that's way harder than I expected. I hope somebody smarter than me will be able to, because the difficulty of it suggests to me that just casting to shared is not a good solution.