zoukankan      html  css  js  c++  java
  • WriteLog

    package com.hgx.test.common;

    /**
    * WriteLog
    *
    * @author sasou <admin@php-gene.com> web:http://www.php-gene.com/
    * @version 1.0.0
    */

    import com.hgx.test.common.GetProperties;

    import java.io.File;
    import java.io.FileOutputStream;
    import java.util.Calendar;

    /**
    * write logString
    *
    /* @param logString
    * @author tower
    */
    public class WriteLog {
    public static String base = null;

    public static void write(String type, String logString) {
    if (base == null) {
    base = System.getProperty("user.dir");
    }

    String current = base + "/logs/";
    try {
    String logFilePathName = null;
    Calendar cd = Calendar.getInstance();
    int year = cd.get(Calendar.YEAR);
    String month = addZero(cd.get(Calendar.MONTH) + 1);
    String day = addZero(cd.get(Calendar.DAY_OF_MONTH));
    String hour = addZero(cd.get(Calendar.HOUR_OF_DAY));
    String min = addZero(cd.get(Calendar.MINUTE));
    String sec = addZero(cd.get(Calendar.SECOND));
    current += year + "-" + month + "-" + day + "/";

    File fileParentDir = new File(current);
    if (!fileParentDir.exists()) {
    fileParentDir.mkdirs();
    }

    logFilePathName = current + type + ".log";

    FileOutputStream fos = new FileOutputStream(logFilePathName, true);
    String time = "[" + year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec + "] ";
    String content = time + logString + " ";
    fos.write(content.getBytes());
    fos.flush();
    fos.close();
    if (GetProperties.system_debug > 0) {
    System.out.println(logString);
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    /**
    * add 0
    *
    * @param i
    * @return
    * @author tower
    */
    public static String addZero(int i) {
    if (i < 10) {
    String tmpString = "0" + i;
    return tmpString;
    } else {
    return String.valueOf(i);
    }
    }

    }
  • 相关阅读:
    Browserify
    PhantomJS:基于WebKit、开源的服务器端JavaScript API
    ruby安装
    ssh tunnel通道
    tomcat部署方法总结
    Tomcat 部署:工程下 META-INF 目录下的 Context.xml
    UVA 674 Coin Change (DP)
    Android入门——电话拨号器和四种点击事件
    matlab reshape函数
    看看走过的路——个人重构
  • 原文地址:https://www.cnblogs.com/heguoxiu/p/10135355.html
Copyright © 2011-2022 走看看