-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
106 additions
and
11 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package hub | ||
|
||
import ( | ||
"bytes" | ||
"net/url" | ||
"testing" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
// MemorySink implements zap.Sink by writing all messages to a buffer. | ||
type MemorySink struct { | ||
*bytes.Buffer | ||
} | ||
|
||
// Implement Close and Sync as no-ops to satisfy the interface. The Write | ||
// method is provided by the embedded buffer. | ||
|
||
func (s *MemorySink) Close() error { return nil } | ||
func (s *MemorySink) Sync() error { return nil } | ||
|
||
var sink *MemorySink | ||
|
||
func newTestLogger(t *testing.T) (*MemorySink, Logger) { | ||
if sink == nil { | ||
sink = &MemorySink{new(bytes.Buffer)} | ||
if err := zap.RegisterSink("memory", func(*url.URL) (zap.Sink, error) { | ||
return sink, nil | ||
}); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
conf := zap.NewProductionConfig() | ||
conf.OutputPaths = []string{"memory://"} | ||
|
||
logger, err := conf.Build() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
return sink, logger | ||
} |
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