Skip to content
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-625282: Make logrus dependency optional or drop it all together #1286

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rickr-sigma
Copy link

Description

The following changes decouple logrs from SFLogger, with the eventual goal to allow per context logging control (in a followup PR) by a user provided SFLogger.

This PR is not (yet) complete but is presented as a proof-of-concept. Further cleanup will be performed if this approach is deemed acceptable. One thing to be aware of is that certain interfaces are no longer supported in particular the functional variants of logging, and the WithTime, WithFields, WithError, Panic and Fatal which were all ONLY being exercised in unit tests.

Checklist

  • Created tests which fail without the change (if possible)
  • Extended the README / documentation, if necessary

@rickr-sigma rickr-sigma requested a review from a team as a code owner January 6, 2025 20:08
Copy link

github-actions bot commented Jan 6, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Comment on lines +54 to +63
params := parseParameters("parameters.json", "testconnection")

// get environment variables
env := func(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
if value, ok := params[key].(string); ok && value != "" {
return value
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is not necessary for the PR but it does allow parameters to be read from the json file as per the README.

@@ -149,7 +149,6 @@ func TestLogToConfiguredFile(t *testing.T) {

logger.Error("Error message")
logger.Warn("Warning message")
logger.Warning("Warning message")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning is basically an alias for Warn so removing it since it clutters the interface otherwise.

Comment on lines -210 to -220
func (log *defaultLogger) Fatalf(format string, args ...interface{}) {
if log.enabled {
log.inner.Fatalf(format, args...)
}
}

func (log *defaultLogger) Panicf(format string, args ...interface{}) {
if log.enabled {
log.inner.Panicf(format, args...)
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all Fatal and Panic forms removed from the interface, since they were only used in testing code.

Comment on lines -284 to -288
func (log *defaultLogger) TraceFn(fn rlog.LogFunction) {
if log.enabled {
log.inner.TraceFn(fn)
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all Fn variants removed; again unused in prod code.

Comment on lines -410 to -419
// AddHook adds a hook to the logger hooks.
func (log *defaultLogger) AddHook(hook rlog.Hook) {
log.inner.AddHook(hook)

}

// IsLevelEnabled checks if the log level of the logger is greater than the level param
func (log *defaultLogger) IsLevelEnabled(level rlog.Level) bool {
return log.inner.IsLevelEnabled(level)
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused.

Comment on lines -422 to -434
func (log *defaultLogger) SetFormatter(formatter rlog.Formatter) {
log.inner.SetFormatter(formatter)
}

// SetOutput sets the logger output.
func (log *defaultLogger) SetOutput(output io.Writer) {
log.inner.SetOutput(output)
}

func (log *defaultLogger) SetReportCaller(reportCaller bool) {
log.inner.SetReportCaller(reportCaller)
}

Copy link
Author

@rickr-sigma rickr-sigma Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetFormatter / SetReportCaller only have 1 internal usage and do not need to be part of the interface.

@rickr-sigma
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant