Code example for LogRecord

0
public class LogWriter { 
	public LogWriter(String error) {	
		/** STDERR part */ 
		ConsoleHandler err = new ConsoleHandler();
		Logger log = Logger.getLogger("");
		LogRecord rec = new LogRecord(Level.SEVERE, error);
		err.publish(rec);
		log.addHandler(err);
		err.close();
		 
		/** Log file part */ 
		Calendar cal = Calendar.getInstance();
		error = cal.getTime() + " " + error + "\r\n";
		FileWriter writer;
		try { 
			writer = new FileWriter("logs/error.log", true);
			writer.write(error);
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}