Fix logging colored messages with colored logger

This commit is contained in:
nathanrsxtn
2022-03-01 18:15:27 -07:00
parent 1e573f18e4
commit cd4fd4938a
2 changed files with 4 additions and 2 deletions
@@ -10,6 +10,7 @@ import java.util.Comparator;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.logging.Logger;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.IntStream; import java.util.stream.IntStream;
@@ -24,6 +25,7 @@ import frc4388.utility.CSV;
import frc4388.utility.Gains; import frc4388.utility.Gains;
public class BoomBoom extends SubsystemBase { public class BoomBoom extends SubsystemBase {
private static final Logger LOGGER = Logger.getLogger(BoomBoom.class.getSimpleName());
public WPI_TalonFX m_shooterFalconLeft; public WPI_TalonFX m_shooterFalconLeft;
public WPI_TalonFX m_shooterFalconRight; public WPI_TalonFX m_shooterFalconRight;
public static Gains m_drumShooterGains = ShooterConstants.DRUM_SHOOTER_GAINS; public static Gains m_drumShooterGains = ShooterConstants.DRUM_SHOOTER_GAINS;
@@ -66,7 +68,7 @@ public class BoomBoom extends SubsystemBase {
}; };
m_shooterTable = csv.read(new File(Filesystem.getDeployDirectory(), "Robot Data - Distances.csv").toPath()); m_shooterTable = csv.read(new File(Filesystem.getDeployDirectory(), "Robot Data - Distances.csv").toPath());
new Thread(() -> System.out.println(CSV.ReflectionTable.create(m_shooterTable, RobotBase.isSimulation()))).start(); new Thread(() -> LOGGER.fine(CSV.ReflectionTable.create(m_shooterTable, RobotBase.isSimulation()))).start();
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
// throw new RuntimeException(e); // throw new RuntimeException(e);
@@ -95,7 +95,7 @@ public class AnsiLogging extends ConsoleHandler {
String message = formatMessage(logRecord); String message = formatMessage(logRecord);
String throwable = Optional.ofNullable(logRecord.getThrown()).map(this::makeStackTraceString).orElse(""); String throwable = Optional.ofNullable(logRecord.getThrown()).map(this::makeStackTraceString).orElse("");
String format = levelColors.getOrDefault(logRecord.getLevel().intValue(), levelColors.get(Level.ALL.intValue())); String format = levelColors.getOrDefault(logRecord.getLevel().intValue(), levelColors.get(Level.ALL.intValue()));
return String.format(format, time, source, logRecord.getLevel().getLocalizedName(), message.lines().count() > 1 ? System.lineSeparator() : " ", message, throwable); return String.format(format, time, source, logRecord.getLevel().getLocalizedName(), message.lines().count() > 1 ? System.lineSeparator() : " ", message.contains("\033") ? "\033[0m" + message : message, throwable);
} }
}; };
} }