Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • Let's assume I'm working on a large program and one team wants objects to log with one format and another team wants to log with another format, but both want to log with the same file. I could have the object's constructor instantiate a logger or have a static logger for the class, but then I have the same question of do I make the file path variable and other shared configs global or do I pass it into every class/object? Commented Jul 14, 2023 at 15:20
  • @StaticMethod: whatever suits your requirements best, as long as it keeps the risk of getting unwanted side effects low. Commented Jul 14, 2023 at 15:36
  • I would say that different modules can have different logging requirements if they are running on separate microservices. One deployed service should have a clear requirement that the sys admin can manage. It is the person who executes the deployment who has to care for disk space and all the other details, not the developer. Commented Jul 14, 2023 at 17:22
  • @FluidCode: your comment seems to be off-track, since making the configuration of a logger available to an admin at run time is 100% orthogonal to the decision "global variable vs DI". Or in other words, this has nothing to do with the question. Commented Jul 14, 2023 at 18:41
  • This is also perfectly fine for enormous programs. Logging should just not have side effects or state that can be read. As simple as that. Console.WriteLine is a logger. Unity’s Debug.log is a logger. There might be very special cases and parts where you want to inject your logger but also in large applications it is 99% unnecesary boiler plate. Commented Jul 15, 2023 at 21:30