⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.java

📁 WINAMP的JAVA版本
💻 JAVA
字号:
package javazoom.Util;
import java.io.*;
import java.util.*;

/**
 * This class implements a simple Debug Tool.
 *
 * @author	E.B from JavaZOOM
 * @date	07/10/2001
 *
 * Homepage : http://www.javazoom.net
 *
 *-----------------------------------------------------------------------
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *----------------------------------------------------------------------
 */

public class Debug
{
  private static Debug	_instance = null;
  private PrintWriter 	_out = null;
  private int			_loglevel = 0;

  private Debug()
  {}

  /**
   * Returns Debug instance.
   */
  public synchronized static Debug getInstance()
  {
	  if (_instance == null)
	  {
		_instance = new Debug();
	  }
	  return _instance;
  }

  /**
   * Inits log file.
   */
  public synchronized void init(String filename, int level)
  {
  	_loglevel = level;
  	try
  	{
		_out = new PrintWriter(new FileOutputStream(filename));
	} catch (IOException ioe)
	  {
		System.err.println("Cannot open log file : "+ioe.getMessage());
	  }
  }

  /**
   * Closes log file.
   */
  public synchronized void close()
  {
	if (_out != null)
	{
	  	try
	  	{
			_out.flush();
			_out.close();
		} catch (Exception ioe)
	      {
			System.err.println("Cannot close log file : "+ioe.getMessage());
	  	  }
    }
  }

  /**
   * Sets log level.
   */
  public void setLogLevel(int level)
  {
	  _loglevel = level;
  }

  /**
   * Sends message to log file.
   */
  public synchronized void log(int level, String msg)
  {
	  if (_loglevel >= level)
	  {
		 if (_out != null)
		 {
		  	_out.println(msg);
		  	_out.flush();
	  	 }
	  	 else
	 	 {
			  System.err.println(msg);
	 	 }
	  }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -