fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.io.PrintStream;
  7.  
  8. public class Main {
  9. public static void main(String args[]) {
  10. System.setOut(new PrintStream(System.out) {
  11.  
  12. private StackTraceElement getCallSite() {
  13. for (StackTraceElement e : Thread.currentThread()
  14. .getStackTrace())
  15. if (!e.getMethodName().equals("getStackTrace")
  16. && !e.getClassName().equals(getClass().getName()))
  17. return e;
  18. return null;
  19. }
  20.  
  21. @Override
  22. public void println(String s) {
  23. println((Object) s);
  24. }
  25.  
  26. @Override
  27. public void println(Object o) {
  28. StackTraceElement e = getCallSite();
  29. String callSite = e == null ? "??" : e.getFileName() + ":"
  30. + e.getLineNumber();
  31. super.println(o + "\t\t[" + callSite + "]");
  32. }
  33. });
  34.  
  35. System.out.println("Hello world");
  36. printStuff();
  37. }
  38.  
  39. public static void printStuff() {
  40. System.out.println("More output!");
  41. }
  42. }
  43.  
Success #stdin #stdout 0.09s 320320KB
stdin
Standard input is empty
stdout
Hello world		[Main.java:35]
More output!		[Main.java:40]