Add turnon and turnoff commands to logger
MODIFY
WalletWasabi.Tests/CryptoTests.cs
WalletWasabi.Tests/CryptoTests.cs
@@ -45,10 +45,9 @@ namespace WalletWasabi.Tests
Assert.NotEqual(toEncrypt, encypted);
decrypted = StringCipher.Decrypt(encypted, password);
Assert.Equal(toEncrypt, decrypted);
- var restoreLogMinLevel = Logger.MinimumLevel;
- Logger.SetMinimumLevel(LogLevel.Critical);
+ Logger.TurnOff();
Assert.Throws<CryptographicException>(() => StringCipher.Decrypt(encypted, "wrongpassword"));
- Logger.SetMinimumLevel(restoreLogMinLevel);
+ Logger.TurnOn();
}
[Fact]

MODIFY
WalletWasabi.Tests/ExternalApiTests.cs
WalletWasabi.Tests/ExternalApiTests.cs
@@ -43,10 +43,9 @@ namespace WalletWasabi.Tests
Assert.Contains("AUD", rates.Select(x => x.Code));
Assert.Contains("USD", rates.Select(x => x.Code));
- var restoreLogMinLevel = Logger.MinimumLevel;
- Logger.SetMinimumLevel(LogLevel.Critical);
+ Logger.TurnOff();
await Assert.ThrowsAsync<HttpRequestException>(async () => await client.PushTransactionAsync(new Transaction(), CancellationToken.None));
- Logger.SetMinimumLevel(restoreLogMinLevel);
+ Logger.TurnOn();
}
}

MODIFY
WalletWasabi.Tests/KeyManagementTests.cs
WalletWasabi.Tests/KeyManagementTests.cs
@@ -45,10 +45,9 @@ namespace WalletWasabi.Tests
var sameManager = new KeyManager(manager.EncryptedSecret, manager.ChainCode, manager.ExtPubKey);
var sameManager2 = new KeyManager(manager.EncryptedSecret, manager.ChainCode, password);
- var restoreLogMinLevel = Logger.MinimumLevel;
- Logger.SetMinimumLevel(LogLevel.Critical);
+ Logger.TurnOff();
Assert.Throws<SecurityException>(() => new KeyManager(manager.EncryptedSecret, manager.ChainCode, "differentPassword"));
- Logger.SetMinimumLevel(restoreLogMinLevel);
+ Logger.TurnOn();
Assert.Equal(manager.ChainCode, sameManager.ChainCode);
Assert.Equal(manager.EncryptedSecret, sameManager.EncryptedSecret);
@@ -96,10 +95,9 @@ namespace WalletWasabi.Tests
var filePath = Path.Combine(SharedFixture.DataDir, nameof(CanSerialize), "Wallet.json");
DeleteFileAndDirectoryIfExists(filePath);
- var restoreLogMinLevel = Logger.MinimumLevel;
- Logger.SetMinimumLevel(LogLevel.Critical);
+ Logger.TurnOff();
Assert.Throws<FileNotFoundException>(() => KeyManager.FromFile(filePath));
- Logger.SetMinimumLevel(restoreLogMinLevel);
+ Logger.TurnOn();
manager.ToFile(filePath);

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -106,15 +106,14 @@ namespace WalletWasabi.Tests
var content = new StringContent($"'{signedTx.ToHex()}'", Encoding.UTF8, "application/json");
- var restoreLogMinLevel = Logger.MinimumLevel;
- Logger.SetMinimumLevel(LogLevel.Critical);
+ Logger.TurnOff();
using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
using (var response = await client.SendAsync(HttpMethod.Post, "/api/v1/btc/blockchain/broadcast", content))
{
Assert.NotEqual(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
- Logger.SetMinimumLevel(restoreLogMinLevel);
+ Logger.TurnOn();
}
[Fact]
@@ -126,15 +125,14 @@ namespace WalletWasabi.Tests
var tx = await Global.RpcClient.GetRawTransactionAsync(utxo.OutPoint.Hash);
var content = new StringContent($"'{tx.ToHex()}'", Encoding.UTF8, "application/json");
- var restoreLogMinLevel = Logger.MinimumLevel;
- Logger.SetMinimumLevel(LogLevel.Critical);
+ Logger.TurnOff();
using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
using (var response = await client.SendAsync(HttpMethod.Post, "/api/v1/btc/blockchain/broadcast", content))
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("\"Transaction is already in the blockchain.\"", await response.Content.ReadAsStringAsync());
}
- Logger.SetMinimumLevel(restoreLogMinLevel);
+ Logger.TurnOn();
}
[Fact]
@@ -142,8 +140,7 @@ namespace WalletWasabi.Tests
{
var content = new StringContent($"''", Encoding.UTF8, "application/json");
- var restoreLogMinLevel = Logger.MinimumLevel;
- Logger.SetMinimumLevel(LogLevel.Critical);
+ Logger.TurnOff();
using (var client = new TorHttpClient(new Uri(RegTestFixture.BackendEndPoint)))
using (var response = await client.SendAsync(HttpMethod.Post, "/api/v1/btc/blockchain/broadcast", content))
{
@@ -151,7 +148,7 @@ namespace WalletWasabi.Tests
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
Assert.Equal("\"Invalid hex.\"", await response.Content.ReadAsStringAsync());
}
- Logger.SetMinimumLevel(restoreLogMinLevel);
+ Logger.TurnOn();
}
#endregion
@@ -1042,8 +1039,7 @@ namespace WalletWasabi.Tests
new WalletService.Operation(scp, Money.Satoshis(5), "")
};
- var restoreLogMinLevel = Logger.MinimumLevel;
- Logger.SetMinimumLevel(LogLevel.Critical);
+ Logger.TurnOff();
// toSend cannot be null
await Assert.ThrowsAsync<ArgumentNullException>(async () => await wallet.BuildTransactionAsync(null, null, 0));
@@ -1137,7 +1133,7 @@ namespace WalletWasabi.Tests
// `Custom change` and `spend all` cannot be specified at the same time
await Assert.ThrowsAsync<ArgumentException>(async () => await wallet.BuildTransactionAsync(null, operations, 2, false, null, Script.Empty));
- Logger.SetMinimumLevel(restoreLogMinLevel);
+ Logger.TurnOn();
operations = new[] { new WalletService.Operation(scp, Money.Coins(0.5m), "") };
btx = await wallet.BuildTransactionAsync("password", operations, 2);
@@ -1147,7 +1143,7 @@ namespace WalletWasabi.Tests
Assert.True(btx.FeePercentOfSent > 20);
Assert.Single(btx.SpentCoins);
Assert.Equal(txid, btx.SpentCoins.First().TransactionId);
- Assert.False(btx.Transaction.Transaction.RBF); // Is this okay
+ Assert.False(btx.Transaction.Transaction.RBF);
}
finally
{

MODIFY
WalletWasabi/Logging/Logger.cs
WalletWasabi/Logging/Logger.cs
@@ -12,6 +12,8 @@ namespace WalletWasabi.Logging
{
#region PropertiesAndMembers
+ private static long On = 1;
+
public static LogLevel MinimumLevel { get; private set; } = LogLevel.Critical;
public static HashSet<LogMode> Modes { get; } = new HashSet<LogMode>();
@@ -68,6 +70,10 @@ namespace WalletWasabi.Logging
#region Methods
+ public static void TurnOff() => Interlocked.Exchange(ref On, 0);
+ public static void TurnOn() => Interlocked.Exchange(ref On, 1);
+ public static bool IsOn() => Interlocked.Read(ref On) == 1;
+
public static void DecryptLogEntries(string destination)
{
var encrypted = File.ReadAllText(FilePath);
@@ -92,7 +98,7 @@ namespace WalletWasabi.Logging
{
try
{
- if (Modes.Count == 0)
+ if (Modes.Count == 0 || !IsOn())
{
return;
}

Add turnon and turnoff commands to logger