-
Notifications
You must be signed in to change notification settings - Fork 951
[azcore] Remove logger from azcore #15160
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0920815
initial work, issues with using internal package
seankane-msft 2f50adf
fixing up errors in logger file
seankane-msft e493952
adding logger test file
seankane-msft cfd0b67
removed an example
seankane-msft 411066e
merge conflicts
seankane-msft a0a0446
feedback and removing circular dependency
seankane-msft b168cad
moving logclassification to be in logger, type alias in azcore
seankane-msft 04e8eb6
merge
seankane-msft 12f15a1
update internal version
seankane-msft 597c047
fixes in azcore
seankane-msft eb5517e
fixes to azcore, works now
seankane-msft d776560
linter false positive
seankane-msft 7edca67
catalina's comments
seankane-msft edc132a
more feedback
seankane-msft 138f0fa
update version
seankane-msft c4059cc
Update sdk/azcore/version.go
seankane-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,8 +1,8 @@ | ||
| module github.com/Azure/azure-sdk-for-go/sdk/azcore | ||
|
|
||
| require ( | ||
| github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.1 | ||
| golang.org/x/net v0.0.0-20201010224723-4f7140c49acb | ||
| github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.2 | ||
| golang.org/x/net v0.0.0-20210610132358-84b48f89b13b | ||
| ) | ||
|
|
||
| go 1.14 |
This file contains hidden or 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,15 +1,22 @@ | ||
| github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.1 h1:vx8McI56N5oLSQu8xa+xdiE0fjQq8W8Zt49vHP8Rygw= | ||
| github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.1/go.mod h1:k4KbFSunV/+0hOHL1vyFaPsiYQ1Vmvy1TBpmtvCDLZM= | ||
| golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
| golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | ||
| golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
| golang.org/x/net v0.0.0-20201010224723-4f7140c49acb h1:mUVeFHoDKis5nxCAzoAi7E8Ghb86EXh/RK6wtvJIqRY= | ||
| golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= | ||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
| golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
| golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
| golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= | ||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
| golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= | ||
| golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
| github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.2 h1:E2xwjsWU81O/XuSaxAGa8Jmqz4Vm4NmrpMSO9/XevDg= | ||
| github.com/Azure/azure-sdk-for-go/sdk/internal v0.5.2/go.mod h1:Hl9Vte0DDolj9zqzmfnmY9/zfZbiT5KnvXqVwAvnR8Q= | ||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= | ||
| github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= | ||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
| github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
| golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A= | ||
| golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= | ||
| golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
| golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
| golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
| golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= | ||
| golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
| gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
| gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= | ||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
| gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -6,13 +6,12 @@ | |
| package azcore | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "time" | ||
| "github.com/Azure/azure-sdk-for-go/sdk/internal/logger" | ||
| ) | ||
|
|
||
| // LogClassification is used to group entries. Each group can be toggled on or off. | ||
| type LogClassification string | ||
catalinaperalta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // SetClassifications is used to control which classifications are written to | ||
| // the log. By default all log classifications are writen. | ||
|
||
| type LogClassification logger.LogClassification | ||
seankane-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const ( | ||
| // LogRequest entries contain information about HTTP requests. | ||
|
|
@@ -31,86 +30,38 @@ const ( | |
| LogLongRunningOperation LogClassification = "LongRunningOperation" | ||
| ) | ||
|
|
||
| // Listener is the function signature invoked when writing log entries. | ||
| // A Listener is required to perform its own synchronization if it's | ||
| // expected to be called from multiple Go routines. | ||
| type Listener func(LogClassification, string) | ||
|
|
||
| // Logger controls which classifications to log and writing to the underlying log. | ||
| type Logger struct { | ||
| cls []LogClassification | ||
| lst Listener | ||
| } | ||
|
|
||
| // SetClassifications is used to control which classifications are written to | ||
| // the log. By default all log classifications are written. | ||
| func (l *Logger) SetClassifications(cls ...LogClassification) { | ||
| l.cls = cls | ||
| } | ||
|
|
||
| // SetListener will set the Logger to write to the specified Listener. | ||
| func (l *Logger) SetListener(lst Listener) { | ||
| l.lst = lst | ||
| } | ||
|
|
||
| // Should returns true if the specified log classification should be written to the log. | ||
| // By default all log classifications will be logged. Call SetClassification() to limit | ||
| // the log classifications for logging. | ||
| // If no listener has been set this will return false. | ||
| // Calling this method is useful when the message to log is computationally expensive | ||
| // and you want to avoid the overhead if its log classification is not enabled. | ||
| func (l *Logger) Should(cls LogClassification) bool { | ||
| if l.lst == nil { | ||
| return false | ||
| } | ||
| if l.cls == nil || len(l.cls) == 0 { | ||
| return true | ||
| // the log. By default all log classifications are writen. | ||
| func SetClassifications(cls ...LogClassification) { | ||
seankane-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| input := make([]logger.LogClassification, 0) | ||
| for _, l := range cls { | ||
| input = append(input, logger.LogClassification(l)) | ||
| } | ||
| for _, c := range l.cls { | ||
| if c == cls { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| logger.Log().SetClassifications(input...) | ||
| } | ||
|
|
||
| // Write invokes the underlying Listener with the specified classification and message. | ||
| // If the classification shouldn't be logged or there is no listener then Write does nothing. | ||
| func (l *Logger) Write(cls LogClassification, message string) { | ||
| if !l.Should(cls) { | ||
| return | ||
| } | ||
| l.lst(cls, message) | ||
| } | ||
| // Listener is the function signature invoked when writing log entries. | ||
| // A Listener is required to perform its own synchronization if it's expected to be called | ||
| // from multiple Go routines | ||
| type Listener func(LogClassification, string) | ||
seankane-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Writef invokes the underlying Listener with the specified classification and formatted message. | ||
| // If the classification shouldn't be logged or there is no listener then Writef does nothing. | ||
| func (l *Logger) Writef(cls LogClassification, format string, a ...interface{}) { | ||
| if !l.Should(cls) { | ||
| return | ||
| // transform to convert the azcore.Listener type into a usable one for internal.logger module | ||
| func transform(lst Listener) logger.Listener { | ||
| return func(l logger.LogClassification, msg string) { | ||
| azcoreL := LogClassification(l) | ||
| lst(azcoreL, msg) | ||
| } | ||
| l.lst(cls, fmt.Sprintf(format, a...)) | ||
| } | ||
|
|
||
| // for testing purposes, nolint is a false positive | ||
| func (l *Logger) resetClassifications() { //nolint:unused | ||
| l.cls = nil | ||
| } | ||
|
|
||
| var logger Logger | ||
|
|
||
| // Log returns the process-wide logger. | ||
| func Log() *Logger { | ||
| return &logger | ||
| func SetListener(lst Listener) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: missing doc comment |
||
| if lst == nil { | ||
| logger.Log().SetListener(nil) | ||
| } else { | ||
| logger.Log().SetListener(transform(lst)) | ||
catalinaperalta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| func init() { | ||
| if cls := os.Getenv("AZURE_SDK_GO_LOGGING"); cls == "all" { | ||
| // cls could be enhanced to support a comma-delimited list of log classifications | ||
| logger.lst = func(cls LogClassification, msg string) { | ||
| // simple console logger, it writes to stderr in the following format: | ||
| // [time-stamp] Classification: message | ||
| fmt.Fprintf(os.Stderr, "[%s] %s: %s\n", time.Now().Format(time.StampMicro), cls, msg) | ||
| } | ||
| } | ||
| // for testing purposes | ||
| func resetClassifications() { | ||
| logger.Log().SetClassifications([]logger.LogClassification{}...) | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.