-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #369 from nicolai86/feature/introduce-logging-inte…
…rface Introduce Logger
- Loading branch information
Showing
4 changed files
with
126 additions
and
108 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,49 @@ | ||
// Copyright (C) 2015 Scaleway. All rights reserved. | ||
// 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 { | ||
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 { | ||
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)) | ||
} |
Oops, something went wrong.