Привет, хотел бы улучшить ответ с помощью этого фрагмента кода.
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
public class MyTestLogger {
public static void main(String[] args) throws SecurityException,
IOException {
/*
* The below line is the syntax for the file handler which has the capability of
* appending the logs in the file. The second argument decides the appending.
* FileHandler fileTxt = new FileHandler("eLog.txt", true);
*/
FileHandler fileTxt = new FileHandler("eLog.txt", true);
SimpleFormatter formatter = new SimpleFormatter();
fileTxt.setFormatter(formatter);
Logger LOGGER = Logger.getLogger(MyTestLogger.class.getName());
LOGGER.addHandler(fileTxt);
LOGGER.setLevel(Level.SEVERE);
LOGGER.severe("This is a serious problem !");
}
}
ОК, но теперь он добавляется как новый файл, создавая новый заголовок xml и новый корневой тег .. есть ли способ решить это? –
@Tom Brito - что вы ожидаете от этого? Прочитайте существующий файл, чтобы узнать, имеет ли он заголовок и корневой элемент XML? И как вы предлагаете обеспечить, чтобы файл журнала XML получал закрывающий тег для его корневого элемента? –
@Stephen, если у него нет закрывающего тега, файл поврежден, это не допустимый xml. –