logs.java

来自「java HTTP代理多线程监听和处理连接 java HTTP代理多线程监听」· Java 代码 · 共 58 行

JAVA
58
字号
package proxy;
import java.io.*;
import java.util.*;
import blueSky.util.*;
/**
 * 记录日志
 * @author liwen
 *
 */
public class Logs {
	public Logs() {
		// TODO Auto-generated constructor stub
	}

	public static synchronized void logByte(byte[] bytes, int offset, int len)
			throws IOException {
		System.out.println("//--------------------------start-----------------------//");
		for (int i = 0; i < len; i++) {
			//System.out.print((int) bytes[offset + i]);
		}
		System.out.println("//--------------------------end-------------------------//");
	}
    /** 写字符信息到日志*/
    protected static synchronized void log(String s) {

    	FileOutputStream out = null;
    	String str = BaseFunction.dateToString(new Date()) + ":" + s + "\r\n";
    	try{
	    	out = new FileOutputStream("log.log",true);
	    	out.write(str.getBytes());
    	}catch(Exception ex){
    		System.out.println(BaseFunction.dateToString(new Date()) + ":Write log Exception:" + ex);
    	}finally{
    		try{
    			out.close();
        	}catch(IOException ex){
        		System.out.println(BaseFunction.dateToString(new Date()) + ":Close logfile Exception:" + ex);
        	}
   			
    	}
    	
        //System.out.println(new Date() + ":" + s);
    }
    /**写对象到日志 */

    protected static synchronized void log(Object o) {
        log(o.toString());
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}

⌨️ 快捷键说明

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