This question has been answered and accepted already, but there's another
solution in the limited context of debugging; and it can be probably combined
with existing solutions.
Full disclosure: I've developed Scart, so I am biased; whether or not it's
elegant is a question of taste!
If you want to perform tracing, as opposed to logging, i.e. emit debugging
info for developers and do not want that in the deployed product, you can
try Scart's Expression Tracers.
Actually, they came to existence for the reason you mentioned; to some extent
they can be inserted on the right side of the source code, therefore the clutter
doesn't disappear but is less intrusive. At least that works for me.
I haven't tried the following, but in your use case that may look like:
def myFunc(args) = {
val result = doSomething(args)
log.info("I really ... which is {}", result)
result e_++: s"myFunc($args)"
}
I left the log info, otherwise:
def myFunc(args) = doSomething(args) e_++: s"myFunc($args)"
or rather (Scart uses macros; the compiler gives a warning if this trace is off):
def myFunc(args) = s"myFunc($args)".e_++:
{
doSomething(args)
}
You'll note that I didn't write lengthy trace strings, but Scart automatically
adds information such as class, method names, line# etc. Since it's for
debugging, I personally refer to those and don't need to write very long strings.
There are more options, eventually I ought to document them all.
Also, Scart doesn't require a logger to operate. In order to output its traces within logs, you'll have to designate a printer
function that uses a logger (in the Scart settings object Settings
) which is of type String => Unit
.
Cheers.