goutils/logging/example/example.go

44 lines
1.1 KiB
Go
Raw Normal View History

2015-09-22 17:45:51 +00:00
package main
import (
"os"
"time"
2015-09-22 17:45:51 +00:00
"git.wntrmute.dev/kyle/goutils/logging"
2015-09-22 17:45:51 +00:00
)
var log = logging.NewConsole()
var olog = logging.NewConsole()
2015-09-22 17:45:51 +00:00
func main() {
log.Info("example", "Hello, world.", nil)
log.Warn("example", "this program is about to end", nil)
2015-09-22 17:45:51 +00:00
log.Critical("example", "screaming into the void", nil)
olog.Critical("other", "can anyone hear me?", nil)
2015-09-22 22:14:36 +00:00
log.Warn("example", "but not for long", nil)
2015-09-22 17:45:51 +00:00
log.Info("example", "fare thee well", nil)
olog.Info("other", "all good journeys must come to an end",
map[string]string{"when": time.Now().String()})
2015-09-22 17:45:51 +00:00
log.Info("example", "filelog test", nil)
2015-09-22 17:45:51 +00:00
exampleNewFromFile()
os.Remove("example.log")
os.Remove("example.err")
2015-09-22 17:45:51 +00:00
}
func exampleNewFromFile() {
flog, err := logging.NewSplitFile("example.log", "example.err", true)
2015-09-22 17:45:51 +00:00
if err != nil {
log.Fatal("filelog", "failed to open logger",
map[string]string{"error": err.Error()})
2015-09-22 17:45:51 +00:00
}
flog.Info("filelog", "hello, world", nil)
flog.Info("filelog", "some more things happening", nil)
flog.Warn("filelog", "something suspicious has happened", nil)
flog.Critical("filelog", "pick up that can, Citizen!", nil)
2015-09-22 17:45:51 +00:00
}