Skip to content

Commit

Permalink
Initial start to epilogue
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse committed Aug 5, 2024
1 parent 6db0ff8 commit 8d91881
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 0 deletions.
7 changes: 7 additions & 0 deletions WPILib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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
6 changes: 6 additions & 0 deletions src/epilogue/CustomLoggingForAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Epilogue;

[AttributeUsage(AttributeTargets.Class)]
public sealed class CustomLoggerForAttribute : Attribute {
Type[] Types { get; init; } = [];
}
10 changes: 10 additions & 0 deletions src/epilogue/EpilogueConfiguration.cs
Original file line number Diff line number Diff line change
@@ -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";
}
7 changes: 7 additions & 0 deletions src/epilogue/LogImportance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Epilogue;

public enum LogImportance {
Debug,
Info,
Critical,
}
6 changes: 6 additions & 0 deletions src/epilogue/LogStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Epilogue;

public enum LogStrategy {
OptIn,
OptOut,
}
9 changes: 9 additions & 0 deletions src/epilogue/LoggedAttribute.cs
Original file line number Diff line number Diff line change
@@ -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;
}
51 changes: 51 additions & 0 deletions src/epilogue/Logging/ClassSpecificLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using WPIUtil.Sendable;

namespace Epilogue.Logging;

public abstract class ClassSpecificLogger {
private readonly Dictionary<ISendable, ISendableBuilder> 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.

Check failure on line 29 in src/epilogue/Logging/ClassSpecificLogger.cs

View workflow job for this annotation

GitHub Actions / build-linux (8.x, linux-x64)

Identifier expected

Check failure on line 29 in src/epilogue/Logging/ClassSpecificLogger.cs

View workflow job for this annotation

GitHub Actions / build-linux (8.x, linux-x64)

; expected

Check failure on line 29 in src/epilogue/Logging/ClassSpecificLogger.cs

View workflow job for this annotation

GitHub Actions / build-windows (8.x, win-arm64)

Identifier expected

Check failure on line 29 in src/epilogue/Logging/ClassSpecificLogger.cs

View workflow job for this annotation

GitHub Actions / build-windows (8.x, win-arm64)

; expected
}
}

public abstract class ClassSpecificLogger<T> : 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);
}
}
}
9 changes: 9 additions & 0 deletions src/epilogue/Logging/DataLogger.cs
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 5 additions & 0 deletions src/epilogue/NotLoggedAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Epilogue;

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method)]
public sealed class NotLoggedAttribute : Attribute {
}
17 changes: 17 additions & 0 deletions src/epilogue/epilogue.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Epilogue</RootNamespace>
<AssemblyName>FRC.Epilogue</AssemblyName>
<NoWarn>1591;CA1401;1570</NoWarn>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ntcore\ntcore.csproj" />
<ProjectReference Include="..\wpiutil\wpiutil.csproj" />
</ItemGroup>

</Project>

0 comments on commit 8d91881

Please sign in to comment.