[backend] Logging additions (#24)

* Remove de_pest log level, add instanced shouldLog

* Rename Server, VisionProcess LogGroup to WebServer, VisionModule

* Rename Level to LogLevel

* Added lambda logger methods

* Updated Platform util class, added bootup logging

* Naming fix

* Fix errors, apply spotless

* Apply spotless
This commit is contained in:
Banks T
2020-07-11 22:43:19 -04:00
committed by GitHub
parent a3ee9d8977
commit 9f1899b081
15 changed files with 148 additions and 110 deletions

View File

@@ -19,23 +19,21 @@ package org.photonvision.common.util;
import edu.wpi.first.wpiutil.RuntimeDetector;
import java.io.IOException;
import org.apache.commons.lang3.SystemUtils;
@SuppressWarnings("unused")
public enum Platform {
// WPILib Supported (JNI)
WINDOWS_32("Windows x32"),
WINDOWS_64("Windows x64"),
LINUX_32("Linux x32"),
LINUX_64("Linux x64"),
LINUX_RASPBIAN("Linux Raspbian"), // Raspberry Pi 3/4
LINUX_AARCH64BIONIC("Linux AARCH64 Bionic"), // Jetson Nano, Jetson TX2
MACOS_64("Mac OS x64"),
// ChameleonVision Supported (Manual install)
LINUX_ARM32("Linux ARM32"), // ODROID XU4, C1+
LINUX_ARM64("Linux ARM64"), // ODROID C2, N2
// Completely unsupported
UNSUPPORTED("Unsupported Platform");
LINUX_RASPBIAN("Linux Raspbian"), // TODO: check that RaspiOS reports the same way
LINUX_AARCH64BIONIC("Linux Aarch64 Bionic"),
UNSUPPORTED(
"Unsupported Platform - OS: "
+ SystemUtils.OS_NAME
+ ", Architecture: "
+ SystemUtils.OS_ARCH);
public final String value;
public final boolean isRoot = checkForRoot();
@@ -44,23 +42,14 @@ public enum Platform {
this.value = value;
}
private static final String OS_NAME = System.getProperty("os.name");
private static final String OS_ARCH = System.getProperty("os.arch");
public static final Platform CurrentPlatform = getCurrentPlatform();
private static String UnknownPlatformString =
String.format("Unknown Platform. OS: %s, Architecture: %s", OS_NAME, OS_ARCH);
public boolean isWindows() {
return this == WINDOWS_64 || this == WINDOWS_32;
public static boolean isWindows() {
return CurrentPlatform == WINDOWS_64 || CurrentPlatform == WINDOWS_32;
}
public boolean isLinux() {
return this == LINUX_64 || this == LINUX_RASPBIAN || this == LINUX_ARM64;
}
public boolean isMac() {
return this == MACOS_64;
public static boolean isLinux() {
return CurrentPlatform != UNSUPPORTED && !isWindows();
}
public static boolean isRaspberryPi() {
@@ -71,7 +60,7 @@ public enum Platform {
@SuppressWarnings("StatementWithEmptyBody")
private boolean checkForRoot() {
if (isLinux() || isMac()) {
if (isLinux()) {
try {
shell.execute("id", null, true, "-u");
} catch (IOException e) {
@@ -98,26 +87,17 @@ public enum Platform {
if (RuntimeDetector.is64BitIntel()) return WINDOWS_64;
}
if (RuntimeDetector.isMac()) {
if (RuntimeDetector.is32BitIntel()) return UNSUPPORTED;
if (RuntimeDetector.is64BitIntel()) return MACOS_64;
}
if (RuntimeDetector.isLinux()) {
if (RuntimeDetector.is32BitIntel()) return UNSUPPORTED;
if (RuntimeDetector.is32BitIntel()) return LINUX_32;
if (RuntimeDetector.is64BitIntel()) return LINUX_64;
if (RuntimeDetector.isRaspbian()) return LINUX_RASPBIAN;
if (RuntimeDetector.isAarch64Bionic()) return LINUX_AARCH64BIONIC;
}
System.out.println(UnknownPlatformString);
return Platform.UNSUPPORTED;
return UNSUPPORTED;
}
public String toString() {
if (this.equals(UNSUPPORTED)) {
return UnknownPlatformString;
} else {
return this.value;
}
return this.value;
}
}