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

    }
  • 相关阅读:
    烂泥:KVM使用NAT联网并为VM配置iptables端口转发
    烂泥:CentOS6.5挂载windows共享文件夹
    烂泥:KVM、kickstart与FTP集成
    js-浅显基础-正则表达式集
    小程序-轮播图案例
    小程序-TabBar点击切换
    js-禁止微信内置浏览器调整字体大小
    小程序-分享到群或好友
    小程序-提交信息(姓名,电话)
    js-在url后面添加时间戳清除浏览器打开页面的缓存
  • 原文地址:https://www.cnblogs.com/heguoxiu/p/10135355.html
Copyright © 2011-2022 走看看