Switched to buffered output stream for stdout/stderr.

This commit is contained in:
Erik C. Thauvin 2020-12-04 01:40:20 -08:00
parent ca2939629f
commit 2d24f5fc97

View file

@ -87,6 +87,7 @@ import org.apache.logging.log4j.core.config.Configurator;
import org.jibble.pircbot.PircBot; import org.jibble.pircbot.PircBot;
import org.jibble.pircbot.User; import org.jibble.pircbot.User;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -299,7 +300,6 @@ public class Mobibot extends PircBot {
System.out.println(ReleaseInfo.WEBSITE); System.out.println(ReleaseInfo.WEBSITE);
} else { } else {
final Properties p = new Properties(); final Properties p = new Properties();
try (final InputStream fis = Files.newInputStream( try (final InputStream fis = Files.newInputStream(
Paths.get(commandLine.getOptionValue(Constants.PROPS_ARG.charAt(0), "./mobibot.properties")))) { Paths.get(commandLine.getOptionValue(Constants.PROPS_ARG.charAt(0), "./mobibot.properties")))) {
// Load the properties files // Load the properties files
@ -321,8 +321,8 @@ public class Mobibot extends PircBot {
// Redirect the stdout and stderr // Redirect the stdout and stderr
if (!commandLine.hasOption(Constants.DEBUG_ARG.charAt(0))) { if (!commandLine.hasOption(Constants.DEBUG_ARG.charAt(0))) {
try { try {
final PrintStream stdout = new PrintStream( final PrintStream stdout = new PrintStream(new BufferedOutputStream(new FileOutputStream(
new FileOutputStream(logsDir + channel.substring(1) + '.' + Utils.today() + ".log", true)); logsDir + channel.substring(1) + '.' + Utils.today() + ".log", true)), true);
System.setOut(stdout); System.setOut(stdout);
} catch (IOException e) { } catch (IOException e) {
System.err.println("Unable to open output (stdout) log file."); System.err.println("Unable to open output (stdout) log file.");
@ -331,7 +331,9 @@ public class Mobibot extends PircBot {
} }
try { try {
final PrintStream stderr = new PrintStream(new FileOutputStream(logsDir + nickname + ".err", true)); final PrintStream stderr =
new PrintStream(new BufferedOutputStream(
new FileOutputStream(logsDir + nickname + ".err", true)), true);
System.setErr(stderr); System.setErr(stderr);
} catch (IOException e) { } catch (IOException e) {
System.err.println("Unable to open error (stderr) log file."); System.err.println("Unable to open error (stderr) log file.");
@ -724,7 +726,9 @@ public class Mobibot extends PircBot {
@Override @Override
protected final void onPrivateMessage(final String sender, final String login, final String hostname, protected final void onPrivateMessage(final String sender, final String login, final String hostname,
final String message) { final String message) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(">>> {} : {}", sender, message); LOGGER.debug(">>> {} : {}", sender, message);
}
final String[] cmds = message.split(" ", 2); final String[] cmds = message.split(" ", 2);
final String cmd = lowerCase(cmds[0]); final String cmd = lowerCase(cmds[0]);