📄 recordlog.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -