2015-09-22 10:32:44 +00:00
|
|
|
package logging_test
|
2015-09-22 10:27:14 +00:00
|
|
|
|
2015-09-22 10:32:44 +00:00
|
|
|
import "github.com/kisom/goutils/logging"
|
|
|
|
|
|
|
|
var log = logging.Init()
|
|
|
|
var olog = logging.New("subsystem #42", logging.LevelNotice)
|
2015-09-22 10:27:14 +00:00
|
|
|
|
2015-09-22 10:30:55 +00:00
|
|
|
func Example() {
|
2015-09-22 10:27:14 +00:00
|
|
|
log.Notice("Hello, world.")
|
|
|
|
log.Warning("this program is about to end")
|
|
|
|
|
|
|
|
olog.Print("now online")
|
2015-09-22 10:32:44 +00:00
|
|
|
logging.Suppress("olog")
|
2015-09-22 10:27:14 +00:00
|
|
|
olog.Print("extraneous information")
|
|
|
|
|
2015-09-22 10:32:44 +00:00
|
|
|
logging.Enable("olog")
|
2015-09-22 10:27:14 +00:00
|
|
|
olog.Print("relevant now")
|
|
|
|
|
2015-09-22 10:32:44 +00:00
|
|
|
logging.SuppressAll()
|
2015-09-22 10:27:14 +00:00
|
|
|
log.Alert("screaming into the void")
|
|
|
|
olog.Critical("can anyone hear me?")
|
|
|
|
|
|
|
|
log.Enable()
|
|
|
|
log.Notice("i'm baaack")
|
|
|
|
log.Suppress()
|
|
|
|
log.Warning("but not for long")
|
|
|
|
|
2015-09-22 10:32:44 +00:00
|
|
|
logging.EnableAll()
|
2015-09-22 10:27:14 +00:00
|
|
|
log.Notice("fare thee well")
|
|
|
|
olog.Print("all good journeys must come to an end")
|
|
|
|
}
|
2015-09-22 10:43:33 +00:00
|
|
|
|
|
|
|
func ExampleNewFromFile() {
|
|
|
|
log, err := logging.NewFromFile("file logger", logging.LevelNotice,
|
|
|
|
"example.log", "example.err", true)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("failed to open logger: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Notice("hello, world")
|
|
|
|
log.Notice("some more things happening")
|
|
|
|
log.Warning("something suspicious has happened")
|
|
|
|
log.Alert("pick up that can, Citizen!")
|
|
|
|
}
|