-
Notifications
You must be signed in to change notification settings - Fork 336
feat(go): implement golang sdk logger #3379
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
Open
slash-init
wants to merge
10
commits into
apache:master
Choose a base branch
from
slash-init:feat/go-sdk-logger
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a01f939
feat(go-sdk): add configurable logger interface and integrate through…
slash-init 6e2bd67
fix(go-sdk) : remove duplicate logger field from config struct
slash-init b649bd2
refactor(go-sdk) : use slog directly
slash-init b030657
test(go-sdk): add logger unit tests
slash-init eb85b1f
fix(go) : harden logger helpers, guard nil path, and document transpo…
slash-init fe2473e
refactor(go): unify logger configuration and remove helpers
slash-init 0ed2244
fix(go): guard WithLogger against nil and clean up tests
slash-init c96fa1c
Merge branch 'master' into feat/go-sdk-logger
hubcio 93497bd
test(go-sdk): fix typo in logger test
slash-init 9fcf309
Merge branch 'master' into feat/go-sdk-logger
hubcio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package client | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "log/slog" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestWithLogger_Nil(t *testing.T) { | ||
| cli, err := NewIggyClient(WithLogger(nil)) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error creating client: %v", err) | ||
| } | ||
| ic := cli.(*IggyClient) | ||
| if ic.logger.Handler() != slog.DiscardHandler { | ||
| t.Errorf("expected slog.DiscardHandler, got %v", ic.logger.Handler()) | ||
| } | ||
| } | ||
|
|
||
|
slash-init marked this conversation as resolved.
|
||
| func TestWithLogger_SetsClientLogger(t *testing.T) { | ||
| var buf bytes.Buffer | ||
| logger := slog.New(slog.NewTextHandler(&buf, &slog.HandlerOptions{ | ||
| Level: slog.LevelDebug, | ||
| })) | ||
|
|
||
| cli, err := NewIggyClient(WithLogger(logger)) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error creating client: %v", err) | ||
| } | ||
|
|
||
| ic := cli.(*IggyClient) | ||
|
|
||
| ic.logger.Info("probe message", "key", "value") | ||
|
|
||
| output := buf.String() | ||
| if !strings.Contains(output, "probe message") { | ||
| t.Errorf("expected logger output to contain 'probe message', got: %q", output) | ||
| } | ||
| if !strings.Contains(output, "key=value") { | ||
| t.Errorf("expected logger output to contain 'key=value', got: %q", output) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ import ( | |||||
| "crypto/x509" | ||||||
| "encoding/binary" | ||||||
| "fmt" | ||||||
| "log/slog" | ||||||
| "net" | ||||||
| "os" | ||||||
| "strings" | ||||||
|
|
@@ -51,6 +52,7 @@ type IggyTcpClient struct { | |||||
| conn net.Conn | ||||||
| mtx sync.Mutex | ||||||
| config config | ||||||
| logger *slog.Logger | ||||||
| MessageCompression iggcon.IggyMessageCompression | ||||||
| leaderRedirectionState iggcon.LeaderRedirectionState | ||||||
| clientAddress string | ||||||
|
|
@@ -195,7 +197,7 @@ func WithTLSValidateCertificate(validate bool) TLSOption { | |||||
|
|
||||||
| // NewIggyTcpClient creates a new Iggy TCP client with the given options. | ||||||
| // warning: don't use this function directly, use iggycli.NewIggyClient with iggycli.WithTcp instead. | ||||||
| func NewIggyTcpClient(options ...Option) *IggyTcpClient { | ||||||
| func NewIggyTcpClient(logger *slog.Logger, options ...Option) *IggyTcpClient { | ||||||
| opts := GetDefaultOptions() | ||||||
| for _, opt := range options { | ||||||
| if opt != nil { | ||||||
|
|
@@ -205,6 +207,7 @@ func NewIggyTcpClient(options ...Option) *IggyTcpClient { | |||||
|
|
||||||
| return &IggyTcpClient{ | ||||||
| config: opts.config, | ||||||
| logger: logger, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| clientAddress: "", | ||||||
| conn: nil, | ||||||
| state: iggcon.StateDisconnected, | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.