-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SNOW-834781: Remove log4net and delegate logging to consumers #1057
base: master
Are you sure you want to change the base?
Conversation
…nector-net into SNOW-834781-Remove-log4net # Conflicts: # Snowflake.Data.Tests/IntegrationTests/SFConnectionIT.cs # Snowflake.Data.Tests/UnitTests/Configuration/EasyLoggingConfigFinderTest.cs # Snowflake.Data/Core/ArrowResultSet.cs # Snowflake.Data/Core/FileTransfer/StorageClient/SFGCSClient.cs # Snowflake.Data/Core/HttpUtil.cs # Snowflake.Data/Core/SFBlockingChunkDownloaderV3.cs # Snowflake.Data/Core/SFStatement.cs
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1057 +/- ##
==========================================
+ Coverage 86.24% 86.62% +0.37%
==========================================
Files 132 137 +5
Lines 12672 12844 +172
Branches 1300 1320 +20
==========================================
+ Hits 10929 11126 +197
+ Misses 1417 1397 -20
+ Partials 326 321 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…nector-net into SNOW-834781-Remove-log4net
…nector-net into SNOW-834781-Remove-log4net # Conflicts: # Snowflake.Data/Core/FileTransfer/StorageClient/SFGCSClient.cs
…nector-net into SNOW-834781-Remove-log4net
{ | ||
ILoggerFactory factory = LoggerFactory.Create( | ||
builder => builder | ||
.AddConsole() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it mean that we create a custom logger with logging to console always enabled?
Could we defer the decision about appenders to the customer configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means if a customer enables custom logging without setting their own logger then a console logger will be created
If a customer sets the logger then it will return their custom logger with their chosen appenders (logging to console is not enabled unless they added it themselves)
var repository = (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository(); | ||
var rootLogger = (log4net.Repository.Hierarchy.Logger)repository.GetLogger("Snowflake.Data"); | ||
rootLogger.Level = log4netLevel; | ||
var rootLogger = SFLogRepository.GetRootLogger(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've lost. Could you explain the relation between RootLogger and SFLoggerPair.s_snowflakeLogger?
Why do we need root logger?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SFLoggerPair.s_snowflakeLogger
contains the type/class where the logging is being created (SnowflakeDbConnection
, SnowflakeDbDataReader
, etc.)
The rootLogger
contains the log level and appenders set from ReconfigureEasyLogging
or ResetEasyLogging
If there's no rootLogger
, then calling ReconfigureEasyLogging
would not affect the log level and appenders of SFLoggerPair.s_snowflakeLogger
Since the original log4net used a rootLogger
, I tried to minimize any changes by making SFlogger similar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've refactored it so the log level/appender are static and root logger is no longer necessary. But if you prefer the original way that log4net used to do it let me know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to understand the big picture.
- How the user can register his logger implementation?
- I see that he needs to set SFLoggerFactory.s_customLogger by SnowflakeDbLoggerFactory.SetCustomLogger()
- so the consequence is that the user sets for all drivers's classes the same implementation - is it good?
- I know that for instance in log4net you could define different loggers for different classes
- Is there a way to set different customer loggers for different classes?
- Is there a generic way to register ILogger implementation?
- How does Snowflake logger work?
- I see that SFLoggerPair has a field of _snowflakeLogger
- Once the SFLoggerPair is created, I don't see the way to change the snowflakeLogger
- I see that EasyLogging changes appenders for SFLoggerImpl
- but how Easy Logging would enable logging if the classes would have SFLoggerEmptyImpl implementation in their SFLoggerPair?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that he needs to set SFLoggerFactory.s_customLogger by SnowflakeDbLoggerFactory.SetCustomLogger()
- That's correct
so the consequence is that the user sets for all drivers's classes the same implementation - is it good?
- Yes, it sets the same implementation for all classes
I know that for instance in log4net you could define different loggers for different classes
- Yes, when
log4net
was used directly by the connector it defined different loggers for different classes usingSFLoggerFactory.GetLogger<Class>()
. Now the connector does a similar thing forSFLogger
Is there a way to set different customer loggers for different classes?
- There probably is, maybe a function that adds a custom logger per class. The connector could check a dictionary of custom loggers for that specific class and if not, use the custom logger from
SetCustomLogger
Is there a generic way to register ILogger implementation?
- This was the doc I found but it seems to be specific to HostApplicationBuilder: https://learn.microsoft.com/en-us/dotnet/core/extensions/custom-logging-provider#usage-and-registration-of-the-custom-logger
I see that SFLoggerPair has a field of _snowflakeLogger
Once the SFLoggerPair is created, I don't see the way to change the snowflakeLogger
- It's changed through the appender
I see that EasyLogging changes appenders for SFLoggerImpl
- That's correct
but how Easy Logging would enable logging if the classes would have SFLoggerEmptyImpl implementation in their SFLoggerPair?
- The
SFLoggerEmptyImpl
was done for test purposes and can only be enabled internally. TheSFLoggerImpl
should be whatSFLoggerPair
always uses
{ | ||
internal class SFLoggerPair : SFLogger | ||
{ | ||
private readonly SFLogger s_snowflakeLogger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not static but has prefix s_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed
…nector-net into SNOW-834781-Remove-log4net # Conflicts: # Snowflake.Data.Tests/UnitTests/Logger/SFLoggerTest.cs # Snowflake.Data/Configuration/SFConfigurationSectionHandler.cs # Snowflake.Data/Core/SFBlockingChunkDownloaderV3.cs # Snowflake.Data/Logger/Log4netImpl.cs # Snowflake.Data/Logger/SFLogger.cs # Snowflake.Data/Logger/SFLoggerEmptyImpl.cs # Snowflake.Data/Logger/SFLoggerFactory.cs
Description
Remove the log4net dependency and replace with the Microsoft logging interface so users can plug in their own custom loggers
Checklist
dotnet test
)