Olá, estou fazendo um controle de log, gostaria de gravar o mesmo em txt, consegui criar a classe e gravar no txt mas não esta gravando da forma que eu gostaria segue metodo.
public ControleLog(Exception excecao) {
File diretorio = new File("C:\\log\\");
if (!diretorio.exists())
diretorio.mkdir();
File arquivoLog = new File(diretorio,"log" + new SimpleDateFormat("yyyy-MM-dd-hh.mm.ss").format(Calendar.getInstance(Locale.getDefault()).getTime()).toString()+".txt");
PrintWriter printWriter;
try {
printWriter = new PrintWriter(arquivoLog);
// Pega a data e hora do log.
printWriter.println(new SimpleDateFormat("EEEE, d MMMM yyyy hh:mm:ss").format(Calendar.getInstance(Locale.getDefault()).getTime()));
printWriter.println();
printWriter.println(excecao);
printWriter.close();
// Responsavel por mostrar a exceção no console
excecao.printStackTrace();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
Classe para teste :
public class Teste {
public static void main(String[] args) {
try {
int a = Integer.parseInt("A");
} catch (Exception e) {
new ControleLog(e);
}
}
}
Gostaria que no txt fosse gravado o que aparece no console.
esta classe de Teste gera o seguinte erro:
java.lang.NumberFormatException: For input string: "A"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Teste.main(Teste.java:8)
Mas no txt esta gravando apenas
java.lang.NumberFormatException: For input string: "A"
Se alguêm puder me ajudar fico feliz.