In my log entries, I would like to log the function name in which the log method was called.
This is to automatically be able to filter log entries by function name. Is this possible? With any libraries? Any extensions with existing libraries?
In other words, is it possible to extract the name of the scala function the execution context is currently executing at runtime?
Secondary Question: I understand this may be far-fetched, but ideally, the closest enclosing named function which contained the logging call is preferred instead of the actual anonymous function that scala generates a cryptic name for. The latter would be hard to read from logs.
Here is a hack that you could use. It traverses the current stack trace to find the first non-anonymous function.
You can use it like this:
The obvious downside is its fragility. I am not at all sure if the single regex above suffices to ignore all anonymous or otherwise non-interesting functions. And even if, there are no guarantees that the naming schema doesn't change in future Scala versions.