Skip to content

Conversation

@babyTsakhes
Copy link
Collaborator

conn: change design of tarantool.Logger

  • Changed the logging design, now it works with slog.
  • Changed the tests that tested logging.

Closes #504 .

We have used the slog library, and now the messages are more informative.

Closes #504
@babyTsakhes babyTsakhes force-pushed the babyTsakhes/gh-504-change-design-of-tarantool-Logger branch from d32547b to 348e8dc Compare January 27, 2026 08:48
if err = conn.dial(ctx); err == nil {
// Atomically increase the reconnect count
// (use atomic operations for thread safety)
reconnects := atomic.AddUint32(&conn.reconnectCount, 1) - 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you using atomics here? Reconnects cannot be in parallel and dirty reads are not a problem here.

Also, are you sure we need to log reconnect count here? We're creating separate field inside conn, but I don't see use-case here.

}

// Method to reset the reconnect count
func (conn *Connection) resetReconnectCount() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

unused

}

// Method for getting the current number of reconnects
func (conn *Connection) GetReconnectCount() uint32 {
Copy link
Collaborator

@bigbes bigbes Jan 27, 2026

Choose a reason for hiding this comment

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

unused and public

cancel()

if err != nil {
// The error will most likely be the one that Dialer
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure this commentary should be removed?

IsInitial bool
}

func (e ReconnectFailedEvent) EventName() string { return "reconnect_failed" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm sure that EventName() should not be a short tag, since it's logging mechanism. If you want - you may add separate 'short' tag as logging field, but log message should be a properly human-readable message.

If we want to process 'events', there's already another mechanism in connector called 'Notify'.

I've looked into old code and find this kind of logged messages:

1. connection failed
2. last connection failed, giving up // ?? i'm not sure we need separate error, simple (5/5) should give us a same information
3. unable to parse watch event
4. unsupported box.session.push
5. unexpected event

}
}

func (l *SlogLogger) WithContext(ctx context.Context) *SlogLogger {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func (l *SlogLogger) WithContext(ctx context.Context) *SlogLogger {
func (l SlogLogger) WithContext(ctx context.Context) *SlogLogger {

}
}

func (l *SlogLogger) Report(event LogEvent, conn *Connection) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func (l *SlogLogger) Report(event LogEvent, conn *Connection) {
func (l SlogLogger) Report(event LogEvent, conn *Connection) {

Comment on lines +19 to +27
func NewSlogLogger(logger *slog.Logger) *SlogLogger {
if logger == nil {
logger = slog.Default()
}
return &SlogLogger{
logger: logger,
ctx: context.Background(),
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's dead-simple builder wrapper, no need to use ptr here, imo:

Suggested change
func NewSlogLogger(logger *slog.Logger) *SlogLogger {
if logger == nil {
logger = slog.Default()
}
return &SlogLogger{
logger: logger,
ctx: context.Background(),
}
}
func NewSlogLogger(logger *slog.Logger) SlogLogger {
if logger == nil {
logger = slog.Default()
}
return SlogLogger{
logger: logger,
ctx: context.Background(),
}
}

Also add commentary pls

func (e baseEvent) baseAttrs() []slog.Attr {
attrs := []slog.Attr{
slog.String("component", "tarantool.connection"),
slog.Time("time", e.time),
Copy link
Collaborator

@bigbes bigbes Jan 27, 2026

Choose a reason for hiding this comment

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

Do not add time, we're using logger that user passes to us and if he want to see time - he will add time. Add only necessary fields.

If you mean time when we've created physical event - it should be called eventTime. But again - not sure this is really needed, diff between eventTime and "log time" should be very small.

close(conn.control)
atomic.StoreUint32(&conn.state, connClosed)
conn.cond.Broadcast()
// Free the resources.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you removing this code?


select {
case <-ctx.Done():
// Since the context is cancelled, we don't need to do anything.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure this commentary should be removed?

}

func (l *SlogLogger) Report(event LogEvent, conn *Connection) {
attrs := event.LogAttrs()
Copy link
Collaborator

@bigbes bigbes Jan 27, 2026

Choose a reason for hiding this comment

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

Duplicate fields here? For example LogAttrs() returns max_reconnects and then we're appending max_reconnects from conn again.

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.

v3: change design of tarantool.Logger

3 participants