1 /*
   2  *                 Sun Public License Notice
   3  *
   4  * The contents of this file are subject to the Sun Public License
   5  * Version 1.0 (the "License"). You may not use this file except in
   6  * compliance with the License. A copy of the License is available at
   7  * http://www.sun.com/
   8  *
   9  * The Original Code is Variable Highlighter IDE Plugin.
  10  * The Initial Developer of the Original Code is Simeon Zverinski
  11  * All rights reserved.
  12  *
  13  * Copyright (c) 2002, 2003 Simeon Zverinski
  14  */
  15 
  16 package org.varhigh.core;
  17 
  18 import java.io.ByteArrayOutputStream;
  19 import java.io.PrintStream;
  20 import javax.swing.JFrame;
  21 import javax.swing.JScrollPane;
  22 import javax.swing.JTextArea;
  23 
  24 /**
  25  * Debug log.
  26  * Acts as Java Console if the debug attribute is set to true.
  27  * By default does nothing.
  28  *
  29  */
  30 public class Log extends JFrame {
  31   private final static boolean debug = false;
  32   private static Log log = null;
  33   private JTextArea jTextArea = null;
  34 
  35   /**
  36    * Creates a new Log object.
  37    */
  38   protected Log() {
  39     super("Variable Highlighter Log Console");
  40 
  41     if (debug) {
  42       jTextArea = new JTextArea();
  43       this.getContentPane().add(new JScrollPane(jTextArea));
  44       this.setSize(400, 400);
  45       this.show();
  46     }
  47   }
  48 
  49   /**
  50    * Gets single instance of the Log.
  51    *
  52    * @return
  53    */
  54   public synchronized static Log getInstance() {
  55     return (log == null) ? (log = new Log()) : log;
  56   }
  57 
  58   /**
  59    * Prints debug message
  60    *
  61    * @param message
  62    */
  63   public void printDebugMessage(String message) {
  64     if (debug) {
  65       jTextArea.append(message + "\n");
  66     }
  67   }
  68 
  69   /**
  70    * Prints debug message
  71    *
  72    * @param message
  73    * @param e
  74    */
  75   public void printDebugMessage(String message, Throwable e) {
  76     if (debug) {
  77       printDebugMessage(message);
  78       ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  79       PrintStream out = new PrintStream(byteArrayOutputStream);
  80       e.printStackTrace(out);
  81       printDebugMessage(byteArrayOutputStream.toString());
  82     }
  83   }
  84 }


CategoryJava

ZbmonWiki: Log.java (2005-11-07 14:18:44에 zbmon가(이) 마지막으로 수정)