public void TestConsoleLoggingLevel() { Environment.SetEnvironmentVariable("hazelcast.logging.level", "info"); var logger = new ConsoleLogFactory().GetLogger("logger"); var original = Console.Out; try { var memoryStream = new MemoryStream(); var streamWriter = new StreamWriter(memoryStream); Console.SetOut(streamWriter); var message1 = TestSupport.RandomString(); var message2 = TestSupport.RandomString(); logger.Info(message1); logger.Finest(message2); streamWriter.Flush(); memoryStream.Seek(0, SeekOrigin.Begin); var log = new StreamReader(memoryStream).ReadToEnd(); Assert.IsFalse(logger.IsFinestEnabled()); Assert.That(logger.GetLevel(), Is.EqualTo(LogLevel.Info)); Assert.That(log, Is.StringContaining(message1)); Assert.That(log, Is.Not.StringContaining(message2)); } finally { Console.SetOut(original); Environment.SetEnvironmentVariable("hazelcast.logging.level", null); } }
public void TestConsoleLoggingInvalidLevel() { Environment.SetEnvironmentVariable("hazelcast.logging.level", "asdf"); var logger = new ConsoleLogFactory().GetLogger("logger"); Assert.IsFalse(logger.IsFinestEnabled()); }