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.
Comment #1 by elpenguino+D — 2022-11-15T20:27:29Z
Once the 2.101.0 docs are live, the example in question will be found at https://dlang.org/phobos/std_logger.html instead.
Comment #2 by forestix — 2024-05-31T19:45:11Z
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.
Comment #4 by Bastiaan — 2024-07-05T17:33:43Z
Atila has a PR for this, needs rebasing. https://github.com/dlang/phobos/pull/8783.
Comment #5 by dlang-bot — 2024-07-20T20:26:41Z
@veelo updated dlang/phobos pull request #8995 "Correct documentation." fixing this issue: - Update documentation. Fix Bugzilla 23487 - std.experimental.logger assigning FileLogger to sharedLog no longer works https://github.com/dlang/phobos/pull/8995
Comment #6 by dlang-bot — 2024-07-21T22:47:44Z
dlang/phobos pull request #8995 "Fix sharedLog assignment." was merged into stable: - df00b0816bbaa0d076a0b5581b182a1f7ee74a40 by Bastiaan Veelo: Update documentation. Fix Bugzilla 23487 - std.experimental.logger assigning FileLogger to sharedLog no longer works https://github.com/dlang/phobos/pull/8995
Comment #7 by dlang-bot — 2024-11-17T01:03:56Z
dlang/phobos pull request #9086 "Merge stable" was merged into master: - 4b61e7dd55200372a3b7e9159a52e378b3ee0e3c by Bastiaan Veelo: Fix sharedLog assignment. (#8995) * Allow `new shared FileLogger()` * Address review comment * Update documentation. Fix Bugzilla 23487 - std.experimental.logger assigning FileLogger to sharedLog no longer works * Comment on `trusted` section. --------- Co-authored-by: Atila Neves <[email protected]> https://github.com/dlang/phobos/pull/9086