2015-09-22 17:45:51 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-04-01 22:08:55 +00:00
|
|
|
"os"
|
|
|
|
"time"
|
2015-09-22 17:45:51 +00:00
|
|
|
|
2020-11-27 04:09:37 +00:00
|
|
|
"git.sr.ht/~kisom/goutils/logging"
|
2015-09-22 17:45:51 +00:00
|
|
|
)
|
|
|
|
|
2016-04-01 22:08:55 +00:00
|
|
|
var log = logging.NewConsole()
|
|
|
|
var olog = logging.NewConsole()
|
2015-09-22 17:45:51 +00:00
|
|
|
|
|
|
|
func main() {
|
2016-04-01 22:08:55 +00:00
|
|
|
log.Info("example", "Hello, world.", nil)
|
|
|
|
log.Warn("example", "this program is about to end", nil)
|
2015-09-22 17:45:51 +00:00
|
|
|
|
2016-04-01 22:08:55 +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
|
|
|
|
2016-04-01 22:08:55 +00:00
|
|
|
log.Warn("example", "but not for long", nil)
|
2015-09-22 17:45:51 +00:00
|
|
|
|
2016-04-01 22:08:55 +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
|
|
|
|
2016-04-01 22:08:55 +00:00
|
|
|
log.Info("example", "filelog test", nil)
|
2015-09-22 17:45:51 +00:00
|
|
|
exampleNewFromFile()
|
2016-04-01 22:08:55 +00:00
|
|
|
os.Remove("example.log")
|
|
|
|
os.Remove("example.err")
|
2015-09-22 17:45:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func exampleNewFromFile() {
|
2016-04-01 22:08:55 +00:00
|
|
|
flog, err := logging.NewSplitFile("example.log", "example.err", true)
|
2015-09-22 17:45:51 +00:00
|
|
|
if err != nil {
|
2016-04-01 22:08:55 +00:00
|
|
|
log.Fatal("filelog", "failed to open logger",
|
|
|
|
map[string]string{"error": err.Error()})
|
2015-09-22 17:45:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-01 22:08:55 +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
|
|
|
}
|