📄 logger.java
字号:
/* * 10/01/2001 - 15:52:00 * * FtpGUI - Ftp client written in Java * Copyright (C) 2001 Kostadin Kirilov Kostadinov * k3co@hotmail.com * sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package ftpgui;/** * Title: FtpGUI * Description: * Copyright: Copyright (c) 2001 * Company: * @author * @version 1.0 */import java.io.*;public class Logger{ private static Logger m_objLogger=null; private static boolean m_booStoreToLogFile=true; private static String m_strFileName=null;//"\\Logfile.txt"; PrintWriter m_objFileOutputStream=null; byte m_bytearEndLine[]="\r\n".getBytes(); public Logger() { if(!m_booStoreToLogFile) return; init(); } private void init() { try { if(m_strFileName==null) { m_booStoreToLogFile=false; if(m_objFileOutputStream!=null) m_objFileOutputStream.close(); m_objFileOutputStream=null; return; } m_objFileOutputStream=new PrintWriter( new FileOutputStream(m_strFileName));// m_objFileOutputStream.close(); }catch(Exception e){e.printStackTrace();} } public static void setLogingInFile(boolean booStoreToLogFile) { m_booStoreToLogFile=booStoreToLogFile; if(m_booStoreToLogFile) { if(m_objLogger!=null) m_objLogger.init(); else m_objLogger=new Logger(); } } public static void setLogFileName(String strFileName) { m_strFileName=strFileName; } public void logToFile(String str) { if(m_objFileOutputStream!=null && m_booStoreToLogFile) { try { m_objFileOutputStream.println(str);//.getBytes()); //m_objFileOutputStream.println(m_bytearEndLine); m_objFileOutputStream.flush(); }catch(Exception e){e.printStackTrace();} } } public void logToScreen(String str) { System.out.println(str); } public static void log(String str) { str=(new java.util.Date()).toLocaleString()+" "+str; if(m_objLogger==null) { m_objLogger=new Logger(); } m_objLogger.logToFile(str); m_objLogger.logToScreen(str); } public static void log(Exception e) { ByteArrayOutputStream objByteArrayOutputStream=new ByteArrayOutputStream(); PrintStream ojbPrintStream=new PrintStream(objByteArrayOutputStream); e.printStackTrace(ojbPrintStream); String strRet=objByteArrayOutputStream.toString(); ojbPrintStream.close(); if(m_objLogger==null) { m_objLogger=new Logger();; } m_objLogger.logToFile(strRet); m_objLogger.logToScreen(strRet); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -