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

Unable to implement custom loggers #443

Open
polastre opened this issue Jan 26, 2025 · 0 comments
Open

Unable to implement custom loggers #443

polastre opened this issue Jan 26, 2025 · 0 comments

Comments

@polastre
Copy link

Two of your types don't allow for implementing custom loggers outside of your package because the fields are internal to the package.

In particular:

type Valuer interface {
	getValue() interface{}
}

If this was instead:

type Valuer interface {
	Value() interface{}
}

then other packages could implement loggers that can access the value of the Valuer. As it is currently written, only loggers you define in your log package can access the value of a Valuer.

I get that you're using Valuer interface to get around passing any, but I think passing any would be better. Instead you've redefined any to be a struct, when newer versions of go already support any aliased to interface{}.

Additionally, LoggedError has internal fields and is not an interface. Recommend that this be changed from a struct to an interface.

type LoggedError struct {
	err error
}

func (l LoggedError) Err() error {
	return l.err
}

func (l LoggedError) Nil() error {
	return nil
}

instead consider:

type LoggedError interface {
	Err() error
	Nil() error
}

type LoggedErrorImpl struct {
	err error
}

func (l LoggedErrorImpl) Err() error {
	return l.err
}

func (l LoggedErrorImpl) Nil() error {
	return nil
}

I'm also not sure I understand the purpose of a Nil() func that always returns nil.

@adamdecaf adamdecaf transferred this issue from moov-io/go-sftp Jan 27, 2025
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

No branches or pull requests

1 participant