Last active
August 29, 2015 14:05
-
-
Save negator/d705b687bcf0b9db3533 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object log { | |
class LineOfCode() { | |
val loc = { | |
val list = Thread.currentThread.getStackTrace.toList | |
list match { | |
case (_ :: _ :: _ :: loc :: loc2 :: _) => s"${loc2.getFileName}:${loc2.getLineNumber}->${loc.getFileName}:${loc.getLineNumber}" | |
case _ => "" | |
} | |
} | |
} | |
def debug(msg: Any)(implicit trace: LineOfCode = new LineOfCode()) = logger debug s"[trace: ${trace.loc}] ${msg.toString}" | |
def info(msg: Any)(implicit trace: LineOfCode = new LineOfCode()) = logger info s"[trace: ${trace.loc}] ${msg.toString}" | |
def warn(msg: Any)(implicit trace: LineOfCode = new LineOfCode()) = logger warn s"[trace: ${trace.loc}] ${msg.toString}" | |
def error(msg: Any, t: Throwable = new RuntimeException("Uncaught error"))(implicit trace: LineOfCode = new LineOfCode()) = logger error (s"[trace: ${trace.loc}] ${msg}", t) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment