-
Notifications
You must be signed in to change notification settings - Fork 152
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
Introduce Logger #369
Introduce Logger #369
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (C) 2015 Scaleway. All rights reserved. | ||
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. package comment should be of the form "Package api ..." |
||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE.md file. | ||
|
||
package api | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
// Logger handles logging concerns for the Scaleway API SDK | ||
type Logger interface { | ||
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. exported type Logger should have comment or be unexported |
||
LogHTTP(*http.Request) | ||
Fatalf(format string, v ...interface{}) | ||
Debugf(format string, v ...interface{}) | ||
Infof(format string, v ...interface{}) | ||
Warnf(format string, v ...interface{}) | ||
} | ||
|
||
// NewDefaultLogger returns a logger which is configured for stdout | ||
func NewDefaultLogger() Logger { | ||
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. exported function NewDefaultLogger should have comment or be unexported |
||
return &defaultLogger{ | ||
Logger: log.New(os.Stdout, "", log.LstdFlags), | ||
} | ||
} | ||
|
||
type defaultLogger struct { | ||
*log.Logger | ||
} | ||
|
||
func (l *defaultLogger) LogHTTP(r *http.Request) { | ||
l.Printf("%s %s\n", r.Method, r.URL.RawPath) | ||
} | ||
func (l *defaultLogger) Fatalf(format string, v ...interface{}) { | ||
l.Printf("[FATAL] %s\n", fmt.Sprintf(format, v)) | ||
os.Exit(1) | ||
} | ||
func (l *defaultLogger) Debugf(format string, v ...interface{}) { | ||
l.Printf("[DEBUG] %s\n", fmt.Sprintf(format, v)) | ||
} | ||
func (l *defaultLogger) Infof(format string, v ...interface{}) { | ||
l.Printf("[INFO ] %s\n", fmt.Sprintf(format, v)) | ||
} | ||
func (l *defaultLogger) Warnf(format string, v ...interface{}) { | ||
l.Printf("[WARN ] %s\n", fmt.Sprintf(format, v)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported method ScalewayAPI.HideAPICredentials should have comment or be unexported