• 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();
    	}


     

  • 相关阅读:
    Yum安装Lamp环境
    Cacti系统监控安装
    源码安装Memcache
    Lamp源码编译+SVN安装
    分页数据列表写法
    文件单位转换函数
    Session写入到Memcache,Redis和数据库中
    [LeetCode#30]Substring with Concatenation of All Words
    快速创建php server
    Git skills in reseting files
  • 原文地址:https://www.cnblogs.com/riasky/p/3473374.html
Copyright © 2020-2023  润新知