Skip to content
This repository was archived by the owner on Jul 21, 2025. It is now read-only.

Conversation

@Kulezi
Copy link
Contributor

@Kulezi Kulezi commented Sep 6, 2022

This PR provides a Logger interface allowing to supply
a custom logger as part of (Session)ConnConfig.

It also provides three implementations of Logger:

  • DefaultLogger, logging only warnings
  • DebugLogger, logging everything that can be useful for debugging,
    it is used by default in tests
  • NopLogger, logging nothing

Fixes #271

@Kulezi Kulezi requested a review from zimnx September 6, 2022 09:57
@Kulezi Kulezi force-pushed the pp/logger branch 3 times, most recently from bcb363a to dffd72c Compare September 6, 2022 10:17
@@ -0,0 +1,69 @@
package transport
Copy link

Choose a reason for hiding this comment

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

how does logger relates to transport? It feels like it belongs to root package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Almost all logging takes place in the transport package, and putting the entire logger inside of scylla package creates an import cycle, transport package should not have dependencies in scylla package.

I suppose Logger interface could be declared identically in both transport and scylla packages instead of aliasing it in scylla package so it shows up as the whole declaration instead of an alias in docs.

It also could have its own package but that seems excessive to me.

Copy link

Choose a reason for hiding this comment

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

Almost all logging takes place in the transport package,

Fact that given package is the biggest client of some package doesn't mean it should be defined there. The point of having separate packages is to split functionality in smaller portions so that they can be consumed without unnecessary bloat.

putting the entire logger inside of scylla package creates an import cycle, transport package should not have dependencies in scylla package.

Then it feels like it deserves a separate package.

I suppose Logger interface could be declared identically in both transport and scylla packages instead of aliasing it in scylla package so it shows up as the whole declaration instead of an alias in docs.

Having "same" declaration in multiple places makes it harder to introduce changes to shared part.

It also could have its own package but that seems excessive to me.

Again, transport has nothing in common with logging. It's just wrong to define it here and then type alias on other places.

@Kulezi Kulezi force-pushed the pp/logger branch 4 times, most recently from e8791b4 to ec3977c Compare September 8, 2022 15:25
if err := ctx.Err(); err != nil {
return nil, fmt.Errorf("aborted opening connection on shard %d: %w", si.Shard, err)
}

Copy link

Choose a reason for hiding this comment

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

Does the second commit (transport: conn, abort OpenShardConn faster when context is done) belong to this PR? It looks like it can be submitted separately and reviewed independently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to #286.

logger/logger.go Outdated
@@ -0,0 +1,69 @@
package logger
Copy link

Choose a reason for hiding this comment

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

Suggested change
package logger
package log

"log" is in sync with other logging packages

@Kulezi Kulezi force-pushed the pp/logger branch 2 times, most recently from 3675270 to 65e6570 Compare September 13, 2022 10:14
@Kulezi Kulezi requested a review from zimnx September 13, 2022 14:11
session.go Outdated
Comment on lines 69 to 80
func NewDefaultLogger() log.Logger {
return log.NewDefaultLogger()
}

func NewDebugLogger() log.Logger {
return log.NewDebugLogger()
}

func NewNopLogger() log.Logger {
return log.NopLogger{}
}

Copy link

Choose a reason for hiding this comment

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

These shouldn't be exposed in root package, users aren't generally interested such details, default session should use default logger. Advanced users who would like to change logging details, can import log package.

The driver now provides a Logger interface allowing to supply
a custom logger as part of (Session)ConnConfig.

Driver also provides three implementations of Logger by itself:
- DefaultLogger, logging only warnings
- DebugLogger, logging everything that can be useful for debugging,
  it is used by default in tests
- NopLogger, logging nothing

Fixes #271
@Kulezi
Copy link
Contributor Author

Kulezi commented Sep 23, 2022

Rebased, renamed the new logging package to log. Integration tests don't fail anymore after #283 was merged.

Please let me know if I can merge this @zimnx.

@Kulezi Kulezi requested a review from zimnx September 23, 2022 09:15
Copy link

@zimnx zimnx left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@Kulezi Kulezi merged commit 5369a73 into main Sep 23, 2022
@Kulezi Kulezi deleted the pp/logger branch September 23, 2022 09:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

session: add log configuration

4 participants