Scala / Spark

How to write Current method name to log in Scala[Code Snippet]

You will be having many methods in your application framework, and if want to trace and log current method name then the below code will be helpful for you.

def getCurrentMethodName:String = Thread.currentThread.getStackTrace()(2).getMethodName
def test{
  println("you are in - "+getCurrentMethodName)
  println("this is doing some functionality")
}
test

Output:
you are in – test
this is doing some functionality

Share This Post

An Ambivert, music lover, enthusiast, artist, designer, coder, gamer, content writer. He is Professional Software Developer with hands-on experience in Spark, Kafka, Scala, Python, Hadoop, Hive, Sqoop, Pig, php, html,css. Know more about him at www.24tutorials.com/sai

Lost Password

Register

24 Tutorials