mirror of
https://github.com/Team4388/2022NoWayHome.git
synced 2026-06-09 08:48:07 -06:00
Change the off logging level to behave properly
Reduce the amount of strings created when logging Add a temporary to do list to the read me file
This commit is contained in:
@@ -563,28 +563,30 @@ public class DriverStation {
|
||||
boolean printTrace,
|
||||
StackTraceElement[] stackTrace,
|
||||
int stackTraceFirst) {
|
||||
if (!frc4388.utility.AnsiLogging.LEVEL.equals(java.util.logging.Level.OFF)) {
|
||||
java.util.logging.LogRecord logRecord = new java.util.logging.LogRecord(isError ? java.util.logging.Level.SEVERE : java.util.logging.Level.FINER, error.stripTrailing());
|
||||
logRecord.setLoggerName("HAL");
|
||||
if (!frc4388.utility.AnsiLogging.halLoggerHandler.isLoggable(logRecord)) return;
|
||||
java.util.Optional.ofNullable(stackTrace).filter(s -> s.length >= stackTraceFirst + 1).map(s -> java.util.Arrays.copyOfRange(s, Math.min(Math.max(0, stackTraceFirst), s.length - 1), s.length - 1)).ifPresent(presentStackTrace -> {
|
||||
logRecord.setSourceMethodName(presentStackTrace[0].getMethodName());
|
||||
String throwableMessage;
|
||||
if (presentStackTrace[0].toString().equals("edu.wpi.first.wpilibj.Tracer.lambda$printEpochs$0(Tracer.java:63)")) {
|
||||
throwableMessage = "Epochs" + System.lineSeparator() + logRecord.getMessage();
|
||||
presentStackTrace = new java.lang.StackTraceElement[0];
|
||||
logRecord.setLevel(java.util.logging.Level.FINEST);
|
||||
logRecord.setMessage("Execution times:");
|
||||
} else if (printTrace) {
|
||||
long lineCount = logRecord.getMessage().lines().count();
|
||||
throwableMessage = (lineCount > 1 ? logRecord.getMessage().lines().findFirst().map(s -> s + " + " + lineCount + " more lines...").orElse("") : logRecord.getMessage()).stripLeading();
|
||||
} else return;
|
||||
java.lang.Throwable throwable = new java.lang.Throwable(throwableMessage);
|
||||
throwable.setStackTrace(presentStackTrace);
|
||||
logRecord.setThrown(throwable);
|
||||
});
|
||||
if (!frc4388.utility.AnsiLogging.halLoggerHandler.isLoggable(logRecord)) return;
|
||||
frc4388.utility.AnsiLogging.halLoggerHandler.publish(logRecord);
|
||||
if (frc4388.utility.AnsiLogging.halLoggerHandler != null) {
|
||||
if (!frc4388.utility.AnsiLogging.LEVEL.equals(java.util.logging.Level.OFF)) {
|
||||
java.util.logging.LogRecord logRecord = new java.util.logging.LogRecord(isError ? java.util.logging.Level.SEVERE : java.util.logging.Level.FINER, error.stripTrailing());
|
||||
logRecord.setLoggerName("HAL");
|
||||
if (!frc4388.utility.AnsiLogging.halLoggerHandler.isLoggable(logRecord)) return;
|
||||
java.util.Optional.ofNullable(stackTrace).filter(s -> s.length >= stackTraceFirst + 1).map(s -> java.util.Arrays.copyOfRange(s, Math.min(Math.max(0, stackTraceFirst), s.length - 1), s.length - 1)).ifPresent(presentStackTrace -> {
|
||||
logRecord.setSourceMethodName(presentStackTrace[0].getMethodName());
|
||||
String throwableMessage;
|
||||
if (presentStackTrace[0].toString().equals("edu.wpi.first.wpilibj.Tracer.lambda$printEpochs$0(Tracer.java:63)")) {
|
||||
throwableMessage = "Epochs" + System.lineSeparator() + logRecord.getMessage();
|
||||
presentStackTrace = new java.lang.StackTraceElement[0];
|
||||
logRecord.setLevel(java.util.logging.Level.FINEST);
|
||||
logRecord.setMessage("Execution times:");
|
||||
} else if (printTrace) {
|
||||
long lineCount = logRecord.getMessage().lines().count();
|
||||
throwableMessage = (lineCount > 1 ? logRecord.getMessage().lines().findFirst().map(s -> s + " + " + lineCount + " more lines...").orElse("") : logRecord.getMessage()).stripLeading();
|
||||
} else return;
|
||||
java.lang.Throwable throwable = new java.lang.Throwable(throwableMessage);
|
||||
throwable.setStackTrace(presentStackTrace);
|
||||
logRecord.setThrown(throwable);
|
||||
});
|
||||
if (!frc4388.utility.AnsiLogging.halLoggerHandler.isLoggable(logRecord)) return;
|
||||
frc4388.utility.AnsiLogging.halLoggerHandler.publish(logRecord);
|
||||
}
|
||||
} else {
|
||||
String locString;
|
||||
if (stackTrace.length >= stackTraceFirst + 1) {
|
||||
|
||||
@@ -14,7 +14,6 @@ import com.revrobotics.CANSparkMax.IdleMode;
|
||||
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
|
||||
|
||||
import edu.wpi.first.util.sendable.SendableRegistry;
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.Servo;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.Spark;
|
||||
import frc4388.robot.Constants.ClimberConstants;
|
||||
|
||||
@@ -35,9 +35,8 @@ public class AnsiLogging {
|
||||
public static final Level LEVEL = Level.ALL;
|
||||
private static final AnsiPrintStream ANSI_CONSOLE_STREAM = AnsiConsole.err();
|
||||
|
||||
public static Handler halLoggerHandler = new ConsoleHandler();
|
||||
public static Handler halLoggerHandler = null;
|
||||
public static void systemInstall() {
|
||||
if (LEVEL.equals(Level.OFF)) return;
|
||||
try {
|
||||
// Configure java.util.logging.Logger to output additional colored information.
|
||||
LogManager.getLogManager().updateConfiguration(key -> (o, n) -> {
|
||||
@@ -60,7 +59,6 @@ public class AnsiLogging {
|
||||
DurianPlugins.register(Errors.Plugins.Log.class, e -> Logger.getLogger(e.getStackTrace()[0].getClassName().substring(e.getStackTrace()[0].getClassName().lastIndexOf('.') + 1)).log(Level.SEVERE, e, e::getLocalizedMessage));
|
||||
// Store the handler for HAL to use when sending errors to DriverStation.
|
||||
halLoggerHandler = new LoggingAnsiConsoleHandler(new HalOutputStream());
|
||||
// Logger.getLogger(name)
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace(AnsiConsole.sysErr());
|
||||
}
|
||||
@@ -132,7 +130,7 @@ public class AnsiLogging {
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
String s = toString();
|
||||
if (!s.isBlank()) logger.logp(level, null, source, toString());
|
||||
if (!s.isBlank()) logger.logp(level, null, source, s);
|
||||
reset();
|
||||
}
|
||||
}, true);
|
||||
@@ -146,8 +144,7 @@ public class AnsiLogging {
|
||||
}
|
||||
@Override
|
||||
public void flush() {
|
||||
String s = toString();
|
||||
HAL.sendError(false, 0, false, s.substring(0, s.length() - 1), "", "", true);
|
||||
HAL.sendError(false, 0, false, new String(buf, 0, count - 1), "", "", true);
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user