Last active
September 4, 2015 03:13
-
-
Save mexisme/58482424d48b03521c79 to your computer and use it in GitHub Desktop.
Golang Log Testing (Loggly)
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
package main | |
import ( | |
log "github.com/Sirupsen/logrus" | |
"github.com/rifflock/lfshook" | |
//"github.com/sebest/logrusly" | |
"os" | |
"time" | |
) | |
func init() { | |
// Set-up flags | |
// Output to stderr instead of stdout, could also be a file. | |
log.SetOutput(os.Stderr) | |
/* | |
// Output-hook for Loggly | |
hostname, err := os.Hostname() | |
check(err) | |
log.AddHook(logrusly.NewLogglyHook("LOGGLY TOKEN", log.DebugLevel, "test", "directly")) | |
*/ | |
// Output-hook for local files (instead of using an os.Writer for log.SetOutput) | |
log.AddHook((lfshook.NewHook(lfshook.PathMap{ | |
log.DebugLevel: "./test.log", | |
log.InfoLevel: "./test.log", | |
log.WarnLevel: "./test.log", | |
log.ErrorLevel: "./test.log", | |
log.FatalLevel: "./test.log", | |
}))) | |
// Only log the warning severity or above. | |
log.SetLevel(log.DebugLevel) | |
} | |
func check(e error) { | |
if e != nil { | |
panic(e) | |
} | |
} | |
func main() { | |
for i := 0; i < 10; i++ { | |
log.WithFields(log.Fields{"count": i}).Debug("Test") | |
time.Sleep(500 * time.Millisecond) | |
} | |
log.Fatal("KABOOM!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment