-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into weave_1.1_readme_updates
Conflicts: README.md
- Loading branch information
Showing
90 changed files
with
7,092 additions
and
922 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
package common | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
func init() { | ||
InitLogging(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr) | ||
InitDefaultLogging(false) | ||
} |
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 |
---|---|---|
@@ -1,46 +1,62 @@ | ||
package common | ||
|
||
import ( | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
"bytes" | ||
"fmt" | ||
"os" | ||
) | ||
"strings" | ||
|
||
const ( | ||
standardLogFlags = log.Ldate | log.Ltime | log.Lmicroseconds | ||
"github.com/Sirupsen/logrus" | ||
) | ||
|
||
// Largely taken from | ||
// http://www.goinggo.net/2013/11/using-log-package-in-go.html | ||
type textFormatter struct { | ||
} | ||
|
||
// Based off logrus.TextFormatter, which behaves completely | ||
// differently when you don't want colored output | ||
func (f *textFormatter) Format(entry *logrus.Entry) ([]byte, error) { | ||
b := &bytes.Buffer{} | ||
|
||
levelText := strings.ToUpper(entry.Level.String())[0:4] | ||
timeStamp := entry.Time.Format("2006/01/02 15:04:05.000000") | ||
if len(entry.Data) > 0 { | ||
fmt.Fprintf(b, "%s: %s %-44s ", levelText, timeStamp, entry.Message) | ||
for k, v := range entry.Data { | ||
fmt.Fprintf(b, " %s=%v", k, v) | ||
} | ||
} else { | ||
// No padding when there's no fields | ||
fmt.Fprintf(b, "%s: %s %s", levelText, timeStamp, entry.Message) | ||
} | ||
|
||
b.WriteByte('\n') | ||
return b.Bytes(), nil | ||
} | ||
|
||
var ( | ||
Debug *log.Logger | ||
Info *log.Logger | ||
Warning *log.Logger | ||
Error *log.Logger | ||
debugF bool | ||
standardTextFormatter = &textFormatter{} | ||
) | ||
|
||
func InitLogging(debugHandle io.Writer, | ||
infoHandle io.Writer, | ||
warningHandle io.Writer, | ||
errorHandle io.Writer) { | ||
var ( | ||
Log *logrus.Logger | ||
) | ||
|
||
Debug = log.New(debugHandle, "DEBUG: ", standardLogFlags) | ||
Info = log.New(infoHandle, "INFO: ", standardLogFlags) | ||
Warning = log.New(warningHandle, "WARNING: ", standardLogFlags) | ||
Error = log.New(errorHandle, "ERROR: ", standardLogFlags) | ||
func InitLogging(level logrus.Level) { | ||
if Log == nil { | ||
Log = &logrus.Logger{ | ||
Out: os.Stderr, | ||
Formatter: standardTextFormatter, | ||
Hooks: make(logrus.LevelHooks), | ||
Level: level, | ||
} | ||
} | ||
Log.Level = level | ||
} | ||
|
||
func InitDefaultLogging(debug bool) { | ||
if debug == debugF { | ||
return | ||
} | ||
debugF = debug | ||
debugOut := ioutil.Discard | ||
level := logrus.InfoLevel | ||
if debug { | ||
debugOut = os.Stderr | ||
level = logrus.DebugLevel | ||
} | ||
InitLogging(debugOut, os.Stdout, os.Stdout, os.Stderr) | ||
InitLogging(level) | ||
} |
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
Oops, something went wrong.