This is one of those questions that really wouldn't be worth anyone's time under normal circumstances but...
The built in Android logging framework uses seperate methods for log messages of different debug levels. So you have a method android.util.Log.v
for verbose, android.util.Log.e
for errors, and so forth.
Now, I'm maintaining a wrapper class that was built around this, and essentially implements each method and each signature seperately.
The wrapper has finally come in handy because certain functionality needs to be added each time the log is called. However what this means now is that this functionality needs to be duplicated for each and every method signature! And of course one of the red flags of programming is when you find yourself cut-n-pasting a block of code over several methods.
Ordinarily this would be solved by having a general method that takes the logging level as a parameter, switching within the method body for the different android.util.Log
calls, and implementing any "beforelog" and "afterlog" functionality in a single location.
However it occurred to me that logging is extremely delicate because it impacts the performance of the entire application and this is an app that NEEDS to be performant, even on the crappiest of phones. Switching between different log levels for each and every call seems to me as though it would introduce a significant performance hit....or would it? considering an expensive log call is going to be performed anyway.
My question is:
If switching would make things more maintainable but less performant
and cut n paste would make things faster but ugly and more error prone
is there indeed an elegant solution that would serve both purposes?