Closed Osiris-Team closed 3 years ago
Found a solution (tested on jansi 2.2):
/**
* Returns a new {@link BufferedWriter} for the given file.
* This writer is ANSI free, thus perfectly suitable for log files.
* @param file File to write to.
*/
private static BufferedWriter getBufferedWriterForFile(File file) throws Exception {
AnsiConsole.systemInstall(); // To make sure that the console is running
AnsiPrintStream origOut = AnsiConsole.out();
AnsiOutputStream out = new AnsiOutputStream(
new FileOutputStream(file),
origOut.getMode(),
null,
origOut.getType(),
origOut.getColors(),
Charset.defaultCharset(),
null,
null,
true
);
return new BufferedWriter(new OutputStreamWriter(out));
}
For older versions of jansi:
/**
* Returns a new {@link BufferedWriter} for the given file.
* This writer is ANSI free, thus perfectly suitable for log files.
* @param file File to write to.
*/
private static BufferedWriter getBufferedWriterForFile(File file) throws Exception {
AnsiConsole.systemInstall(); // To make sure that the console is running
AnsiOutputStream out = new AnsiOutputStream(new FileOutputStream(file));
return new BufferedWriter(new OutputStreamWriter(out));
}
What's the recommended way of doing this? Couldn't find a simple answer by myself... Context: I have my own custom log file writer