张世豪
5 小时以前 a6077217e25f5804027194a5c2848e773eda1abd
src/dialog/Errlog.java
copy from src/xitongshezhi/Charulog.java copy to src/dialog/Errlog.java
Îļþ´Ó src/xitongshezhi/Charulog.java ¸´ÖÆ
@@ -1,12 +1,12 @@
package xitongshezhi;
package dialog;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
public class Charulog {
    private static final String LOG_FILE = "log.properties";
public class Errlog {
    private static final String LOG_FILE = "err.properties";
    private static final int MAX_RECORDS = 500;
    private static final ReentrantLock lock = new ReentrantLock();
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -51,8 +51,9 @@
        File file = new File(LOG_FILE);
        
        if (file.exists()) {
            try (FileInputStream fis = new FileInputStream(file)) {
                props.load(fis);
            try (FileInputStream fis = new FileInputStream(file);
                 InputStreamReader isr = new InputStreamReader(fis, "UTF-8")) {
                props.load(isr);
            } catch (IOException e) {
                System.err.println("读取日志文件失败: " + e.getMessage());
            }
@@ -95,14 +96,14 @@
     * å†™å…¥æ—¥å¿—文件
     */
    private static void writeLogFile(Properties props) {
        try (FileOutputStream fos = new FileOutputStream(LOG_FILE)) {
        try (FileOutputStream fos = new FileOutputStream(LOG_FILE);
             OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8")) {
            // æ·»åŠ æ–‡ä»¶å¤´æ³¨é‡Š
            props.store(fos, "操作日志记录 - æœ€åŽæ›´æ–°: " + new Date());
            props.store(osw, "操作日志记录 - æœ€åŽæ›´æ–°: " + new Date());
        } catch (IOException e) {
            System.err.println("写入日志文件失败: " + e.getMessage());
        }
    }
    /**
     * èŽ·å–å½“å‰æ—¥å¿—è®°å½•æ•°é‡ï¼ˆç”¨äºŽæµ‹è¯•ï¼‰
     */