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

    }
  • 相关阅读:
    【Appium】appium踩坑记录:解决每次安装appium setting和Unlock
    Pycharm from XXX import XXX 引入本地文件标红报错(source_path&Python package)
    🍖02 不同平台更换pip源
    🍖pycharm 更换 pip 下载源
    🍖01 路飞学城项目分析
    🍖Vue-cli 创建项目
    🍖Vue 与后端交互
    🍖Vue 计算属性
    🍖Vue 虚拟DOM与Diff算法简介
    🍖Vue 生命期钩子
  • 原文地址:https://www.cnblogs.com/heguoxiu/p/10135355.html
Copyright © 2020-2023  润新知