[sf-perl] Logging: per-object, per-package, kinda-global?

George Hartzell hartzell at alerce.com
Fri Apr 5 15:49:03 PDT 2013


Hi All,

We can all agree that globals are evil, right?  (you there in back,
put your hand down, I'm trying to make a point...).

I'm looking at logging and am (once again) playing with a couple of
the strategies that package on CPAN enable.

On the one hand I can simply give each of my classes a logger
attribute and pass one in on construction, or use a default.  Works
reasonably well with any of the packages I'm looking at (::Log4j,
::Dispatchouli).  It's kind of a pain to always be passing them into
constructors and (while not a problem for this particular project) it
could be a scaling problem.

On the other hand I could use Log::Any to generate a package specific
logger, backed by any of the various Log::Any::Adapter::* packages.

On the gripping hand, I could use Log::Dispatchouli::Global, which I
only recently came to understand.  I'd dismissed it earlier because I
thought is simply declared a global logger.  It's tricky (and I was
wrong), one creates a subclass of Log::Dispatchouli::Global and uses
that.  This effectively generates a global within a namespace that one
controls, so other packages are unlikely to step on it.

I can probably guess how Jon (the Log::Any author) will vote.

What approach are others among you using?

g.



More information about the SanFrancisco-pm mailing list