-
Notifications
You must be signed in to change notification settings - Fork 822
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor internal log package (#15265)
Shortened package name to log. Renamed types to remove stuttering. Made logger implementation unexported. Moved logger methods to funcs to simplify API.
- Loading branch information
1 parent
837195d
commit 04b833c
Showing
3 changed files
with
87 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package log | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestLoggingdefault(t *testing.T) { | ||
// ensure logging with nil listener doesn't fail | ||
SetListener(nil) | ||
Write(Request, "this should work just fine") | ||
|
||
log := map[Classification]string{} | ||
SetListener(func(cls Classification, msg string) { | ||
log[cls] = msg | ||
}) | ||
const req = "this is a request" | ||
Write(Request, req) | ||
const resp = "this is a response: %d" | ||
Writef(Response, resp, http.StatusOK) | ||
if l := len(log); l != 2 { | ||
t.Fatalf("unexpected log entry count: %d", l) | ||
} | ||
if log[Request] != req { | ||
t.Fatalf("unexpected log request: %s", log[Request]) | ||
} | ||
if log[Response] != fmt.Sprintf(resp, http.StatusOK) { | ||
t.Fatalf("unexpected log response: %s", log[Response]) | ||
} | ||
} | ||
|
||
func TestLoggingClassification(t *testing.T) { | ||
log := map[Classification]string{} | ||
SetListener(func(cls Classification, msg string) { | ||
log[cls] = msg | ||
}) | ||
SetClassifications(Request) | ||
defer TestResetClassifications() | ||
Write(Response, "this shouldn't be in the log") | ||
if s, ok := log[Response]; ok { | ||
t.Fatalf("unexpected log entry %s", s) | ||
} | ||
const req = "this is a request" | ||
Write(Request, req) | ||
if log[Request] != req { | ||
t.Fatalf("unexpected log entry: %s", log[Request]) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.