From 8d918812229cc0fb40b84693a055be673ead2322 Mon Sep 17 00:00:00 2001 From: Thad House Date: Sun, 4 Aug 2024 18:22:46 -0700 Subject: [PATCH] Initial start to epilogue --- WPILib.sln | 7 +++ src/epilogue/CustomLoggingForAttribute.cs | 6 +++ src/epilogue/EpilogueConfiguration.cs | 10 ++++ src/epilogue/LogImportance.cs | 7 +++ src/epilogue/LogStrategy.cs | 6 +++ src/epilogue/LoggedAttribute.cs | 9 ++++ src/epilogue/Logging/ClassSpecificLogger.cs | 51 +++++++++++++++++++++ src/epilogue/Logging/DataLogger.cs | 9 ++++ src/epilogue/NotLoggedAttribute.cs | 5 ++ src/epilogue/epilogue.csproj | 17 +++++++ 10 files changed, 127 insertions(+) create mode 100644 src/epilogue/CustomLoggingForAttribute.cs create mode 100644 src/epilogue/EpilogueConfiguration.cs create mode 100644 src/epilogue/LogImportance.cs create mode 100644 src/epilogue/LogStrategy.cs create mode 100644 src/epilogue/LoggedAttribute.cs create mode 100644 src/epilogue/Logging/ClassSpecificLogger.cs create mode 100644 src/epilogue/Logging/DataLogger.cs create mode 100644 src/epilogue/NotLoggedAttribute.cs create mode 100644 src/epilogue/epilogue.csproj diff --git a/WPILib.sln b/WPILib.sln index d9d6dfde..85fef836 100644 --- a/WPILib.sln +++ b/WPILib.sln @@ -47,6 +47,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "vbTest", "dev\vbTest\vbTest EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "newcommands", "src\newcommands\newcommands.csproj", "{B09918CC-E71F-4E49-AA20-81559D3583B2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "epilogue", "src\epilogue\epilogue.csproj", "{B8A9AFC6-01F1-44AC-95D4-0683EF31E117}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -128,6 +130,10 @@ Global {B09918CC-E71F-4E49-AA20-81559D3583B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {B09918CC-E71F-4E49-AA20-81559D3583B2}.Release|Any CPU.ActiveCfg = Release|Any CPU {B09918CC-E71F-4E49-AA20-81559D3583B2}.Release|Any CPU.Build.0 = Release|Any CPU + {B8A9AFC6-01F1-44AC-95D4-0683EF31E117}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B8A9AFC6-01F1-44AC-95D4-0683EF31E117}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B8A9AFC6-01F1-44AC-95D4-0683EF31E117}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B8A9AFC6-01F1-44AC-95D4-0683EF31E117}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {8F38C25E-641E-47FC-AC0A-0717F2159E8F} = {DB664556-4BF0-4874-8CB6-DC24E60A67AF} @@ -147,5 +153,6 @@ Global {CC242C8A-93D4-4083-9C3C-D98A1FE687C1} = {1CA9AB3B-4828-4F07-8C0E-88EF7C5A9ACD} {A364B855-95A2-435D-A627-A25F1215AB4E} = {1CA9AB3B-4828-4F07-8C0E-88EF7C5A9ACD} {B09918CC-E71F-4E49-AA20-81559D3583B2} = {DB664556-4BF0-4874-8CB6-DC24E60A67AF} + {B8A9AFC6-01F1-44AC-95D4-0683EF31E117} = {DB664556-4BF0-4874-8CB6-DC24E60A67AF} EndGlobalSection EndGlobal diff --git a/src/epilogue/CustomLoggingForAttribute.cs b/src/epilogue/CustomLoggingForAttribute.cs new file mode 100644 index 00000000..3db14033 --- /dev/null +++ b/src/epilogue/CustomLoggingForAttribute.cs @@ -0,0 +1,6 @@ +namespace Epilogue; + +[AttributeUsage(AttributeTargets.Class)] +public sealed class CustomLoggerForAttribute : Attribute { + Type[] Types { get; init; } = []; +} \ No newline at end of file diff --git a/src/epilogue/EpilogueConfiguration.cs b/src/epilogue/EpilogueConfiguration.cs new file mode 100644 index 00000000..dad8fef9 --- /dev/null +++ b/src/epilogue/EpilogueConfiguration.cs @@ -0,0 +1,10 @@ +using NetworkTables; + +namespace Epilogue; + +public class EpilogueConfiguration { + public DataLogger DataLogger { get; set; } = new NTDataLogger(NetworkTableInstance.Default); + public LogImportance MinimumImportance { get; set; } = LogImportance.Debug; + public ErrorHandler ErrorHandler { get; set; } = new(); + public string Root { get; set; } = "Robot"; +} \ No newline at end of file diff --git a/src/epilogue/LogImportance.cs b/src/epilogue/LogImportance.cs new file mode 100644 index 00000000..316e3261 --- /dev/null +++ b/src/epilogue/LogImportance.cs @@ -0,0 +1,7 @@ +namespace Epilogue; + +public enum LogImportance { + Debug, + Info, + Critical, +} \ No newline at end of file diff --git a/src/epilogue/LogStrategy.cs b/src/epilogue/LogStrategy.cs new file mode 100644 index 00000000..381b45ea --- /dev/null +++ b/src/epilogue/LogStrategy.cs @@ -0,0 +1,6 @@ +namespace Epilogue; + +public enum LogStrategy { + OptIn, + OptOut, +} \ No newline at end of file diff --git a/src/epilogue/LoggedAttribute.cs b/src/epilogue/LoggedAttribute.cs new file mode 100644 index 00000000..e0e7d3da --- /dev/null +++ b/src/epilogue/LoggedAttribute.cs @@ -0,0 +1,9 @@ +namespace Epilogue; + +[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct)] +public sealed class LoggedAttribute : Attribute +{ + public string Name { get; init; } = ""; + public LogStrategy Strategy { get; init; } = LogStrategy.OptOut; + public LogImportance Importance { get; init; } = LogImportance.Debug; +} \ No newline at end of file diff --git a/src/epilogue/Logging/ClassSpecificLogger.cs b/src/epilogue/Logging/ClassSpecificLogger.cs new file mode 100644 index 00000000..ba0f8898 --- /dev/null +++ b/src/epilogue/Logging/ClassSpecificLogger.cs @@ -0,0 +1,51 @@ +using WPIUtil.Sendable; + +namespace Epilogue.Logging; + +public abstract class ClassSpecificLogger { + private readonly Dictionary m_sendables = []; + + protected ClassSpecificLogger(Type loggedType) { + LoggedType = loggedType; + } + + public bool Disabled { get; private set; } + + public void Disable() { + Disabled = true; + } + + public void Reenable() { + Disabled = false; + } + + public Type LoggedType { get; } + + protected virtual void LogSendable(DataLogger dataLogger, ISendable? sendable) { + if (sendable == null) { + return; + } + + var builder = m_sendables. + } +} + +public abstract class ClassSpecificLogger : ClassSpecificLogger { + protected ClassSpecificLogger() : base(typeof(T)) + { + } + + protected abstract void Update(DataLogger dataLogger, T obj); + + public void TryUpdate(DataLogger dataLogger, T obj, ErrorHandler errorHandler) { + if (Disabled) { + return; + } + + try { + Update(dataLogger, obj); + } catch (Exception e) { + errorHandler(e, this); + } + } +} diff --git a/src/epilogue/Logging/DataLogger.cs b/src/epilogue/Logging/DataLogger.cs new file mode 100644 index 00000000..c397bec1 --- /dev/null +++ b/src/epilogue/Logging/DataLogger.cs @@ -0,0 +1,9 @@ +namespace Epilogue.Logging; + +public interface DataLogger { + public static DataLogger Multi(params DataLogger[] loggers) { + return new MultiLogger(loggers); + } + + public DataLogger Lazy => new LazyLogger(this); +} \ No newline at end of file diff --git a/src/epilogue/NotLoggedAttribute.cs b/src/epilogue/NotLoggedAttribute.cs new file mode 100644 index 00000000..bf34f3ee --- /dev/null +++ b/src/epilogue/NotLoggedAttribute.cs @@ -0,0 +1,5 @@ +namespace Epilogue; + +[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method)] +public sealed class NotLoggedAttribute : Attribute { +} \ No newline at end of file diff --git a/src/epilogue/epilogue.csproj b/src/epilogue/epilogue.csproj new file mode 100644 index 00000000..0ebec4a9 --- /dev/null +++ b/src/epilogue/epilogue.csproj @@ -0,0 +1,17 @@ + + + + Epilogue + FRC.Epilogue + 1591;CA1401;1570 + true + latest + true + + + + + + + +