guardian/guardian-management — pull request #6 by bmjames (2012-04-17 15:08:59+00:00)
Title: Empty and no-op timing metrics

At face value, `TimingMetric.empty` looks like a useful way to get a throwaway instance of a `TimingMetric` for, say, a test. In fact, because it's a `val` on a singleton object, it's a piece of global mutable state, so you can only safely use it once in your entire application.

Furthermore, because `TimingMetric.empty` is the default value for an optional parameter to `Timing.debug` and `Timing.info`, if you use these methods anywhere without providing your own value, you're unwittingly mutating that global instance.

The above problems are easily fixed by making it a `def`, but then if you are using the aforementioned methods with the default parameter, you'll creating a new instance each time which seems OTT for something that appears to be intended as a no-op.

Changing the method signature to take an `Option[TimingMetric]` might be nice, but for the sake of not breaking compatibility, I've left the signature as it is, and implemented a `NoOpTimingMetric` instead. Those methods now take a global instance of this by default, which has a `private[management]` access modifier so as not to pollute the API.