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

dhcpv4: server4: Add a simple logging implementation #375

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions dhcpv4/server4/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,21 @@ func (d DebugLogger) Printf(format string, v ...interface{}) {
func (d DebugLogger) PrintMessage(prefix string, message *dhcpv4.DHCPv4) {
d.Printf("%s: %s", prefix, message.Summary())
}

// SimpleLogger is a straight-forward implementation of the new Logger
// interface, for anyone who wishes to wrap logging simply, without having to
// use the complicated interface directly. Just pass in your desired printf
// function, and off you go!
type SimpleLogger struct {
Logf func(format string, v ...interface{})
}

// Printf does what you'd expect, except it does so to your configured function.
func (obj *SimpleLogger) Printf(format string, v ...interface{}) {
obj.Logf(format, v...)
}

// PrintMessage prints to your configured function.
func (obj *SimpleLogger) PrintMessage(prefix string, message *dhcpv4.DHCPv4) {
obj.Logf("%s: %s", prefix, message)
}