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

feat: replace *log.Logger with interface for tc #186

Closed
wants to merge 2 commits into from

Conversation

nddq
Copy link

@nddq nddq commented Dec 12, 2024

Replace the default logger used in tc with an interface instead. Add some tests to verify that other loggers such as zap and logrus are able to satisfy the interface.

Addressed #143

nddq added 2 commits December 12, 2024 17:09
Replace the default logger used in tc with an interface instead. Add some tests to verify that other loggers
such as zap and logrus are able to satisfy the interface.

Signed-off-by: Quang Nguyen <[email protected]>
@florianl
Copy link
Owner

florianl commented Dec 13, 2024

Thanks for taking on #143. When creating the issue, the idea was to introduce logging with various levels. But in the current code base logging is hardly used and there is also no request or need to add more logging. On the contrary, there are more requests for lightweight dependencies.

Therefore, would you mind updating the PR in a way, that it removes logging instead of replacing it with a interface?

For the existing log messages in the code, it could look something like this:

@@ -108,8 +108,7 @@ func (tc *Tc) action(action int, flags netlink.HeaderFlags, msg interface{}, opt
 
        for _, msg := range msgs {
                if msg.Header.Type == netlink.Error {
-                       // see https://www.infradead.org/~tgr/libnl/doc/core.html#core_errmsg
-                       tc.logger.Printf("received netlink.Error in action()\n")
+                       return fmt.Errorf("received netlink Error: %#v", msg)
                }
        }
 
@@ -294,7 +293,6 @@ func (tc *Tc) Monitor(ctx context.Context, deadline time.Duration, fn HookFunc)
                                return 0
                        }
                }
-               tc.logger.Printf("Could not receive message: %v\n", err)
                return 1
        })
 }
@@ -362,12 +360,10 @@ func (tc *Tc) monitor(ctx context.Context, deadline time.Duration,
                        for _, msg := range msgs {
                                var monitored Object
                                if err := unmarshalStruct(msg.Data[:20], &monitored.Msg); err != nil {
-                                       tc.logger.Printf("could not extract tc.Msg from %v\n", msg.Data[:20])
                                        continue
                                }
                                if err := extractTcmsgAttributes(int(msg.Header.Type), msg.Data[20:],
                                        &monitored.Attribute); err != nil {
-                                       tc.logger.Printf("could not extract attributes from %v\n", msg.Data[20:36])
                                        continue
                                }
                                if fn(uint16(msg.Header.Type), monitored) != 0 {

@florianl
Copy link
Owner

Resolved with #190

@florianl florianl closed this Dec 21, 2024
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.

2 participants