1 package ch.qos.logback.core.status; 2 3 import java.io.FileNotFoundException; 4 import java.io.FileOutputStream; 5 import java.io.PrintStream; 6 7 public class OnFileStatusListener extends OnPrintStreamStatusListenerBase { 8 9 String filename; 10 PrintStream ps; 11 12 @Override 13 public void start() { 14 if (filename == null) { 15 addInfo("File option not set. Defaulting to \"status.txt\""); 16 filename = "status.txt"; 17 } 18 19 try { 20 FileOutputStream fos = new FileOutputStream(filename, true); 21 ps = new PrintStream(fos, true); 22 } catch (FileNotFoundException e) { 23 addError("Failed to open [" + filename + "]", e); 24 return; 25 } 26 27 super.start(); 28 29 } 30 31 @Override 32 public void stop() { 33 if (!isStarted) { 34 return; 35 } 36 if (ps != null) 37 ps.close(); 38 super.stop(); 39 } 40 41 public String getFilename() { 42 return filename; 43 } 44 45 public void setFilename(String filename) { 46 this.filename = filename; 47 } 48 49 @Override 50 protected PrintStream getPrintStream() { 51 return ps; 52 } 53 54 }