Code example for StringWriter

Methods: toString, write

0
    private static final Formatter THE_FORMATTER = new Formatter() {
        @Override 
        public String format(LogRecord r) { 
            Throwable thrown = r.getThrown(); 
            if (thrown != null) { 
                StringWriter sw = new StringWriter(); 
                PrintWriter pw = new PrintWriter(sw); 
                sw.write(r.getMessage()); 
                sw.write("\n"); 
                thrown.printStackTrace(pw); 
                pw.flush(); 
                return sw.toString(); 
            } else { 
                return r.getMessage(); 
            } 
        } 
    }; 
 
    /** 
     * Constructs a new instance of the Android log handler. 
     */