Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the name of the enclosing source file in Scala 2.11

At compile time, how to retrieve the name of the current source file (where the code is written) in scala 2.11?

like image 425
Luigi Sgro Avatar asked May 18 '15 15:05

Luigi Sgro


1 Answers

Here's a kinda hacky way that actually does the trick:

val srcFile = new Exception().getStackTrace.head.getFileName
println(srcFile)

Source: How do I get the current script or class name in Scala?

like image 84
Mshnik Avatar answered Nov 15 '22 03:11

Mshnik