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

为什么定义的xlog接口要返回error? #249

Open
ryeLearnMore opened this issue Oct 19, 2023 · 1 comment
Open

为什么定义的xlog接口要返回error? #249

ryeLearnMore opened this issue Oct 19, 2023 · 1 comment

Comments

@ryeLearnMore
Copy link

type Logger interface {
SetLevel(name, level string) error

Debug(format string, a ...interface{}) (err error)
Trace(format string, a ...interface{}) (err error)
Notice(format string, a ...interface{}) (err error)
Warn(format string, a ...interface{}) (err error)
Fatal(format string, a ...interface{}) (err error)

Debugx(logID, format string, a ...interface{}) (err error)
Tracex(logID, format string, a ...interface{}) (err error)
Noticex(logID, format string, a ...interface{}) (err error)
Warnx(logID, format string, a ...interface{}) (err error)
Fatalx(logID, format string, a ...interface{}) (err error)

Close()

}

@gongna-au
Copy link
Collaborator

考虑到可能会在写入日志时遇到 I/O 错误,通过返回相应的错误。使得接口能够兼容多种实现,而不需要在接口定义中硬编码错误处理逻辑。

type Logger interface { SetLevel(name, level string) error

Debug(format string, a ...interface{}) (err error)
Trace(format string, a ...interface{}) (err error)
Notice(format string, a ...interface{}) (err error)
Warn(format string, a ...interface{}) (err error)
Fatal(format string, a ...interface{}) (err error)

Debugx(logID, format string, a ...interface{}) (err error)
Tracex(logID, format string, a ...interface{}) (err error)
Noticex(logID, format string, a ...interface{}) (err error)
Warnx(logID, format string, a ...interface{}) (err error)
Fatalx(logID, format string, a ...interface{}) (err error)

Close()

}

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

2 participants