zoukankan      html  css  js  c++  java
  • Java 自定义日志写入

    /**
    	 * 将信息写入到日志
    	 * @param content
    	 * @return
    	 * @throws IOException
    	 */
    	public static boolean writeLog(String className,String ErrorInfo,String ErrorContent){
    		String content=info(className, ErrorInfo, ErrorContent);
    		File fileName = new File(System.getProperty("user.dir")+"/config/log.log");
    		RandomAccessFile mm = null;
    		boolean flag = false;
    		FileOutputStream o = null;
    		try {
    			o = new FileOutputStream(fileName,true);
    			o.write(content.getBytes("utf-8"));
    			o.close();
    			flag = true;
    		} catch (IOException e) {
    			e.printStackTrace();
    		} finally {
    			if (mm != null) {
    				try {
    					mm.close();	
    				} catch (IOException e) {
    					e.printStackTrace();
    				}
    				
    			}
    		}
    		return flag;
    	}  
    
    	/**
    	 * 
    	 * @param className 类名称
    	 * @param ErrorInfo 错误信息
    	 * @param ErrorContent 错误内容
    	 * @return
    	 */
    	public static String info(String className,String ErrorInfo,String ErrorContent){
    		 StringBuffer buffer=new StringBuffer();
    		 Date date = new Date();   
             SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   
             String d = sd.format(date)+"
    ";  
             buffer.append(d);
             buffer.append("错误类名为:").append(className).append("
    ");
             buffer.append("错误信息为:").append(ErrorInfo).append("
    ");
             buffer.append("错误内容为:").append(ErrorContent).append("
    ");
             buffer.append("
    ");
             return buffer.toString();
    	}


     

  • 相关阅读:
    Nginx 服务器安装及配置文件详解
    Linux 之 压缩解压缩
    RPM方式安装MySQL5.6
    Linux 之 搜索
    zabbix客户端安装
    JAVA输出指定目录下的子目录和子文件
    LoadRunner 11 安装破解
    SVN合并操作实践
    (转)SVN分支/合并原理及最佳实践
    MYSQL 免安装版(windows 7/64)
  • 原文地址:https://www.cnblogs.com/riasky/p/3473374.html
Copyright © 2011-2022 走看看