recordlog.java

来自「通过JAVA访问ORACLE数据库的一系列通用工具」· Java 代码 · 共 55 行

JAVA
55
字号
package client.chaowei.intraweb.bean.util;

import java.io.*;

import java.text.SimpleDateFormat;

import java.util.*;


public final class RecordLog {
  // 决定是否记录日志的变量
  private static boolean isRecord = true;

  public RecordLog() {
  }

  public static void println(String log) {
    if (isRecord) {
      // 日志文件路径
      String logFile = "";
      String s; // 流中介字符串

      try {
		String countFilePath = "/var/opt/SUNWappserver7/domains/domain1/server1/docroot/intrawebdoc/jnpcwebini/config.ini";
		FileInputStream fis = new FileInputStream(countFilePath);
        Properties prop = new Properties();
        prop.load(fis);

        // 服务器日志文件路径
        logFile = prop.getProperty("log_file");

        // 创建字符串输入流
        BufferedReader br = new BufferedReader(new StringReader(log));

        // 创建文件输出流
        PrintWriter pw = new PrintWriter(new FileWriter(logFile, true));
        Date d = new Date();

        // 转换日期格式为:"yyyyMMddhhmmss"
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
        String now = sdf.format(d);

        // 输出到文件
        while ((s = br.readLine()) != null) {
          pw.println(now + " : " + s);
          pw.close();
        }
      } catch (Exception e) {
        System.out.println(e.getMessage());
      }
       //try语句结束
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?