-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Epilogue; | ||
|
||
public enum LogImportance { | ||
Debug, | ||
Info, | ||
Critical, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Epilogue; | ||
|
||
public enum LogStrategy { | ||
OptIn, | ||
OptOut, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / build-linux (8.x, linux-x64)
Check failure on line 29 in src/epilogue/Logging/ClassSpecificLogger.cs GitHub Actions / build-linux (8.x, linux-x64)
Check failure on line 29 in src/epilogue/Logging/ClassSpecificLogger.cs GitHub Actions / build-windows (8.x, win-arm64)
|
||
} | ||
} | ||
|
||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |