Advertisement
hhac

Otro loger mas

Nov 25th, 2022
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1.  
  2. /*
  3. Online Java - IDE, Code Editor, Compiler
  4.  
  5. Online Java is a quick and easy tool that helps you to build, compile, test your programs online.
  6. */
  7. import java.util.Date;
  8. import java.lang.StackTraceElement;
  9.  
  10. public class Main
  11. {
  12.     public static void main(String[] args) {
  13.         Logger.debug("Welcome to Online IDE!! Happy Coding :)");
  14.  
  15.         new Thread(new Runnable(){
  16.            public void run() {
  17.                try {
  18.                    Thread.sleep(1000);
  19.                } catch(Exception e) {
  20.                    
  21.                }
  22.                new BadAssLogic().badAssMethod();
  23.            }
  24.         }, "BadAssThread").start();
  25.  
  26.         new BadAssLogic().badAssMethod();
  27.     }
  28.    
  29.     private static class BadAssLogic {
  30.         public void badAssMethod() {
  31.             Logger.debug("Let's do some bad ass!");
  32.         }
  33.     }
  34.    
  35.     private static class Logger {
  36.         public static void debug(String message) {
  37.             try {
  38.                 long threadid = Thread.currentThread().getId();
  39.                 String threadName = Thread.currentThread().getName();
  40.                 StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
  41.                 StringBuilder builder = new StringBuilder();
  42.                 builder.append("[" + new Date() + "] [" + threadid + "] [" + threadName + "] " + message).append("\n");
  43.                 for (int i = 2; i < stacktrace.length; i ++) {
  44.                     builder.append(stacktrace[i]).append("\n");
  45.                 }
  46.                 System.out.println(builder.toString());
  47.             } catch (Exception e) {
  48.                 e.printStackTrace();
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement