-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use app.logf() for internal packages for nsqd nsqlookupd nsqadmin
Instead of setting a Logger for github.com/nsqio/nsq/internal packages, pass a logf() function, so it is called with and honors a LogLevel. * internal/clusterinfo/ * internal/http_api/ * internal/protocol/ nsqd lookupPeer also needed to be converted Get rid of interal.app.Logger type, but internal/test/ needs its own Logger definition to avoid circular import with internal/lg/ tests.
- Loading branch information
Showing
15 changed files
with
64 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 |
---|---|---|
@@ -1,36 +1,35 @@ | ||
package http_api | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/nsqio/nsq/internal/app" | ||
"github.com/nsqio/nsq/internal/lg" | ||
) | ||
|
||
type logWriter struct { | ||
app.Logger | ||
logf lg.AppLogFunc | ||
} | ||
|
||
func (l logWriter) Write(p []byte) (int, error) { | ||
l.Logger.Output(2, string(p)) | ||
l.logf(lg.WARN, "%s", string(p)) | ||
return len(p), nil | ||
} | ||
|
||
func Serve(listener net.Listener, handler http.Handler, proto string, l app.Logger) { | ||
l.Output(2, fmt.Sprintf("%s: listening on %s", proto, listener.Addr())) | ||
func Serve(listener net.Listener, handler http.Handler, proto string, logf lg.AppLogFunc) { | ||
logf(lg.INFO, "%s: listening on %s", proto, listener.Addr()) | ||
|
||
server := &http.Server{ | ||
Handler: handler, | ||
ErrorLog: log.New(logWriter{l}, "", 0), | ||
ErrorLog: log.New(logWriter{logf}, "", 0), | ||
} | ||
err := server.Serve(listener) | ||
// theres no direct way to detect this error because it is not exposed | ||
if err != nil && !strings.Contains(err.Error(), "use of closed network connection") { | ||
l.Output(2, fmt.Sprintf("ERROR: http.Serve() - %s", err)) | ||
logf(lg.ERROR, "http.Serve() - %s", err) | ||
} | ||
|
||
l.Output(2, fmt.Sprintf("%s: closing %s", proto, listener.Addr())) | ||
logf(lg.INFO, "%s: closing %s", proto, listener.Addr()) | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,37 +1,36 @@ | ||
package protocol | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"runtime" | ||
"strings" | ||
|
||
"github.com/nsqio/nsq/internal/app" | ||
"github.com/nsqio/nsq/internal/lg" | ||
) | ||
|
||
type TCPHandler interface { | ||
Handle(net.Conn) | ||
} | ||
|
||
func TCPServer(listener net.Listener, handler TCPHandler, l app.Logger) { | ||
l.Output(2, fmt.Sprintf("TCP: listening on %s", listener.Addr())) | ||
func TCPServer(listener net.Listener, handler TCPHandler, logf lg.AppLogFunc) { | ||
logf(lg.INFO, "TCP: listening on %s", listener.Addr()) | ||
|
||
for { | ||
clientConn, err := listener.Accept() | ||
if err != nil { | ||
if nerr, ok := err.(net.Error); ok && nerr.Temporary() { | ||
l.Output(2, fmt.Sprintf("NOTICE: temporary Accept() failure - %s", err)) | ||
logf(lg.WARN, "temporary Accept() failure - %s", err) | ||
runtime.Gosched() | ||
continue | ||
} | ||
// theres no direct way to detect this error because it is not exposed | ||
if !strings.Contains(err.Error(), "use of closed network connection") { | ||
l.Output(2, fmt.Sprintf("ERROR: listener.Accept() - %s", err)) | ||
logf(lg.ERROR, "listener.Accept() - %s", err) | ||
} | ||
break | ||
} | ||
go handler.Handle(clientConn) | ||
} | ||
|
||
l.Output(2, fmt.Sprintf("TCP: closing %s", listener.Addr())) | ||
logf(lg.INFO, "TCP: closing %s", listener.Addr()) | ||
} |
This file contains 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 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 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 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 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 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 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 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
Oops, something went wrong.