| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
"time" |
| 6 |
|
| 7 |
"github.com/kisom/goutils/logging" |
| 8 |
) |
| 9 |
|
| 10 |
var log = logging.NewConsole() |
| 11 |
var olog = logging.NewConsole() |
| 12 |
|
| 13 |
func main() { |
| 14 |
log.Info("example", "Hello, world.", nil) |
| 15 |
log.Warn("example", "this program is about to end", nil) |
| 16 |
|
| 17 |
log.Critical("example", "screaming into the void", nil) |
| 18 |
olog.Critical("other", "can anyone hear me?", nil) |
| 19 |
|
| 20 |
log.Warn("example", "but not for long", nil) |
| 21 |
|
| 22 |
log.Info("example", "fare thee well", nil) |
| 23 |
olog.Info("other", "all good journeys must come to an end", |
| 24 |
map[string]string{"when": time.Now().String()}) |
| 25 |
|
| 26 |
log.Info("example", "filelog test", nil) |
| 27 |
exampleNewFromFile() |
| 28 |
os.Remove("example.log") |
| 29 |
os.Remove("example.err") |
| 30 |
} |
| 31 |
|
| 32 |
func exampleNewFromFile() { |
| 33 |
flog, err := logging.NewSplitFile("example.log", "example.err", true) |
| 34 |
if err != nil { |
| 35 |
log.Fatal("filelog", "failed to open logger", |
| 36 |
map[string]string{"error": err.Error()}) |
| 37 |
} |
| 38 |
|
| 39 |
flog.Info("filelog", "hello, world", nil) |
| 40 |
flog.Info("filelog", "some more things happening", nil) |
| 41 |
flog.Warn("filelog", "something suspicious has happened", nil) |
| 42 |
flog.Critical("filelog", "pick up that can, Citizen!", nil) |
| 43 |
} |