Issue 23487 - std.experimental.logger assigning FileLogger to sharedLog no longer works
Summary: std.experimental.logger assigning FileLogger to sharedLog no longer works
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 All
: P1 regression
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2022-11-15 15:14 UTC by Jan Jurzitza
Modified: 2024-11-17 01:03 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jan Jurzitza 2022-11-15 15:14:31 UTC
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 elpenguino+D 2022-11-15 20:27:29 UTC
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 Forest 2024-05-31 19:45:11 UTC
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 Bastiaan Veelo 2024-07-05 15:49:08 UTC
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 Bastiaan Veelo 2024-07-05 17:33:43 UTC
Atila has a PR for this, needs rebasing. https://github.com/dlang/phobos/pull/8783.
Comment 5 Dlang Bot 2024-07-20 20:26:41 UTC
@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 Dlang Bot 2024-07-21 22:47:44 UTC
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 Dlang Bot 2024-11-17 01:03:56 UTC
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 <atila.neves@gmail.com>

https://github.com/dlang/phobos/pull/9086