From: Chuck Remes Date: 2008-06-26T04:00:01+09:00 Subject: Re: Is it ellegant to use a global variable to store a Logger object? On Jun 25, 2008, at 11:04 AM, Andrea Fazzi wrote: > Robert Dober ha scritto: >> each class would need to have an adapted initialize method, well that >> > > Yes, and indeed this is very annoying. When the system grows up you > have to do with long constructor signatures: > > Foo.new(logger, service, another_service ... ) > > But I wonder if there is a better method to keep things decoupled.. I typically provide a setter on my classes for configuring the log object. Hardly perfect, but it keeps the constructor signatures short. I am liking this suggestion to use a global variable though. I think I'll experiment. On a related note, I'm curious how people solve the problem of turning logging on and off during runtime. I hate code like: logger.log(:debug, "some msg") unless logger.nil? I usually provide a null class for my loggers which silently swallow any messages sent to them if the logging function is disabled. It cleans up the code considerably. Is there another way to solve the problem of turning logging on/off at runtime without lots of conditionals? cr