From 1a48c40ad7b3def916849f07640e670051391ac0 Mon Sep 17 00:00:00 2001 From: benbierens Date: Sat, 7 Oct 2023 09:48:12 +0200 Subject: [PATCH] Example of setting codex log topics for libp2p and discv5 --- ProjectPlugins/CodexPlugin/CodexSetup.cs | 22 ++++++++++----- .../CodexPlugin/CodexStartupConfig.cs | 27 ++++++++++++++++--- Tests/CodexTests/BasicTests/ExampleTests.cs | 3 ++- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/ProjectPlugins/CodexPlugin/CodexSetup.cs b/ProjectPlugins/CodexPlugin/CodexSetup.cs index 6ab4d20..0f9f37f 100644 --- a/ProjectPlugins/CodexPlugin/CodexSetup.cs +++ b/ProjectPlugins/CodexPlugin/CodexSetup.cs @@ -11,11 +11,7 @@ namespace CodexPlugin ICodexSetup At(ILocation location); ICodexSetup WithBootstrapNode(ICodexNode node); ICodexSetup WithLogLevel(CodexLogLevel level); - /// - /// Sets the log level for codex. The default level is INFO and the - /// log level is applied only to the supplied topics. - /// - ICodexSetup WithLogLevel(CodexLogLevel level, params string[] topics); + ICodexSetup WithLogLevel(CodexLogLevel level, CodexLogCustomTopics customTopics); ICodexSetup WithStorageQuota(ByteSize storageQuota); ICodexSetup WithBlockTTL(TimeSpan duration); ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration); @@ -28,6 +24,18 @@ namespace CodexPlugin ICodexSetup WithSimulateProofFailures(uint failEveryNProofs); } + public class CodexLogCustomTopics + { + public CodexLogCustomTopics(CodexLogLevel discV5, CodexLogLevel libp2p) + { + DiscV5 = discV5; + Libp2p = libp2p; + } + + public CodexLogLevel DiscV5 { get; set; } + public CodexLogLevel Libp2p { get; set; } + } + public class CodexSetup : CodexStartupConfig, ICodexSetup { public int NumberOfNodes { get; } @@ -61,10 +69,10 @@ namespace CodexPlugin return this; } - public ICodexSetup WithLogLevel(CodexLogLevel level, params string[] topics) + public ICodexSetup WithLogLevel(CodexLogLevel level, CodexLogCustomTopics customTopics) { LogLevel = level; - LogTopics = topics; + CustomTopics = customTopics; return this; } diff --git a/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs index a3b6314..7a68bc7 100644 --- a/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs +++ b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs @@ -8,7 +8,7 @@ namespace CodexPlugin public string? NameOverride { get; set; } public ILocation Location { get; set; } = KnownLocations.UnspecifiedLocation; public CodexLogLevel LogLevel { get; set; } - public string[]? LogTopics { get; set; } + public CodexLogCustomTopics? CustomTopics { get; set; } public ByteSize? StorageQuota { get; set; } public bool MetricsEnabled { get; set; } public MarketplaceInitialConfig? MarketplaceConfig { get; set; } @@ -22,9 +22,30 @@ namespace CodexPlugin public string LogLevelWithTopics() { var level = LogLevel.ToString()!.ToUpperInvariant(); - if (LogTopics != null && LogTopics.Count() > 0) + if (CustomTopics != null) { - level = $"INFO;{level}: {string.Join(",", LogTopics.Where(s => !string.IsNullOrEmpty(s)))}"; + var discV5Topics = new[] + { + "discv5", + "providers", + "manager", + "cache", + }; + var libp2pTopics = new[] + { + "libp2p", + "multistream", + "switch", + "transport", + "tcptransport", + "semaphore", + "asyncstreamwrapper", + "lpstream" + }; + + level = $"{level};" + + $"{CustomTopics.DiscV5.ToString()!.ToLowerInvariant()}:{string.Join(",", discV5Topics)};" + + $"{CustomTopics.Libp2p.ToString()!.ToLowerInvariant()}:{string.Join(",", libp2pTopics)}"; } return level; } diff --git a/Tests/CodexTests/BasicTests/ExampleTests.cs b/Tests/CodexTests/BasicTests/ExampleTests.cs index 4049b9a..0db9bbb 100644 --- a/Tests/CodexTests/BasicTests/ExampleTests.cs +++ b/Tests/CodexTests/BasicTests/ExampleTests.cs @@ -1,4 +1,5 @@ using CodexContractsPlugin; +using CodexPlugin; using DistTestCore; using GethPlugin; using MetricsPlugin; @@ -13,7 +14,7 @@ namespace Tests.BasicTests [Test] public void CodexLogExample() { - var primary = AddCodex(); + var primary = AddCodex(s => s.WithLogLevel(CodexLogLevel.Trace, new CodexLogCustomTopics(CodexLogLevel.Warn, CodexLogLevel.Warn))); primary.UploadFile(GenerateTestFile(5.MB()));