Skip to content

Commit

Permalink
Disable SF logger by default
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-lf committed Jan 15, 2025
1 parent 294f992 commit 588c1ee
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Snowflake.Data.Tests/UnitTests/Logger/SFLoggerPairTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public void BeforeTest()
public void AfterTest()
{
// Return to default setting
SFLoggerFactory.EnableSFLogger();
SFLoggerFactory.UseDefaultSFLogger();
}

[Test]
public void TestUsingSFLogger()
{
SFLoggerFactory.EnableSFLogger();
SFLoggerFactory.UseDefaultSFLogger();
_loggerPair = SFLoggerFactory.GetLogger<SFLoggerPairTest>();
Assert.IsInstanceOf<SFLoggerPair>(_loggerPair);
}
Expand Down Expand Up @@ -127,11 +127,11 @@ private SFLogger GetLogger(bool isEnabled)
{
if (isEnabled)
{
SFLoggerFactory.EnableSFLogger();
SFLoggerFactory.UseDefaultSFLogger();
}
else
{
SFLoggerFactory.DisableSFLogger();
SFLoggerFactory.UseEmptySFLogger();
}

return SFLoggerFactory.GetLogger<SFLoggerPairTest>();
Expand Down
10 changes: 5 additions & 5 deletions Snowflake.Data.Tests/UnitTests/Logger/SFLoggerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ public static void AfterAll()
public void AfterTest()
{
// Return to default setting
SFLoggerFactory.EnableSFLogger();
SFLoggerFactory.UseDefaultSFLogger();
}

[Test]
public void TestUsingSFLogger()
{
SFLoggerFactory.EnableSFLogger();
SFLoggerFactory.UseDefaultSFLogger();
_logger = SFLoggerFactory.GetSFLogger<SFLoggerTest>();
Assert.IsInstanceOf<SFLoggerImpl>(_logger);
}

[Test]
public void TestUsingEmptyLogger()
{
SFLoggerFactory.DisableSFLogger();
SFLoggerFactory.UseEmptySFLogger();
_logger = SFLoggerFactory.GetSFLogger<SFLoggerTest>();
Assert.IsInstanceOf<SFLoggerEmptyImpl>(_logger);
}
Expand Down Expand Up @@ -173,11 +173,11 @@ private SFLogger GetLogger(bool isEnabled)
{
if (isEnabled)
{
SFLoggerFactory.EnableSFLogger();
SFLoggerFactory.UseDefaultSFLogger();
}
else
{
SFLoggerFactory.DisableSFLogger();
SFLoggerFactory.UseEmptySFLogger();
}

return SFLoggerFactory.GetSFLogger<SFLoggerTest>(false);
Expand Down
18 changes: 12 additions & 6 deletions Snowflake.Data/Logger/SFLoggerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ public class SFLoggerFactory
{
private static bool s_isCustomLoggerEnabled = false;

private static bool s_isSFLoggerEnabled = true;
private static bool s_isSFLoggerEnabled = false;

private static bool s_useDefaultSFLogger = true;

private static ILogger s_customLogger = null;

public static void DisableSFLogger()
public static void UseEmptySFLogger()
{
s_isSFLoggerEnabled = false;
s_useDefaultSFLogger = false;
}

public static void EnableSFLogger()
public static void UseDefaultSFLogger()
{
s_isSFLoggerEnabled = true;
s_useDefaultSFLogger = true;
}

public static void DisableCustomLogger()
Expand Down Expand Up @@ -53,9 +55,13 @@ internal static SFLogger GetLogger<T>()
internal static SFLogger GetSFLogger<T>(bool useFileAppender = true)
{
// If true, return the default/specified logger
if (s_isSFLoggerEnabled)
if (s_useDefaultSFLogger)
{
var logger = new SFLoggerImpl(typeof(T));
if (!s_isSFLoggerEnabled)
{
logger.SetLevel(LoggingEvent.OFF); // Logger is disabled by default and can be enabled by the EasyLogging feature
}
if (useFileAppender)
{
var fileAppender = new SFRollingFileAppender()
Expand Down

0 comments on commit 588c1ee

Please sign in to comment.