This repository was archived by the owner on Aug 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathlogger.go
50 lines (41 loc) · 1.41 KB
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2014 Project Iris. All rights reserved.
//
// The current language binding is an official support library of the Iris
// cloud messaging framework, and as such, the same licensing terms apply.
// For details please see http://iris.karalabe.com/downloads#License
// Contains the user configurable logger instance.
package iris
import (
"fmt"
"time"
"gopkg.in/inconshreveable/log15.v2"
)
// User configurable leveled logger.
var Log = log15.New()
// Disables logging by default.
func init() {
Log.SetHandler(log15.DiscardHandler())
//Log.SetHandler(log15.LvlFilterHandler(log15.LvlCrit, log15.StderrHandler))
//Log.SetHandler(log15.LvlFilterHandler(log15.LvlError, log15.StderrHandler))
Log.SetHandler(log15.LvlFilterHandler(log15.LvlInfo, log15.StderrHandler))
//Log.SetHandler(log15.LvlFilterHandler(log15.LvlDebug, log15.StderrHandler))
}
// Creates a lazy value that flattens and truncates a data blob for logging.
func logLazyBlob(data []byte) log15.Lazy {
return log15.Lazy{func() string {
if len(data) > 256 {
return fmt.Sprintf("%v ...", data[:256])
}
return fmt.Sprintf("%v", data)
}}
}
// Creates a lazy value that flattens a timeout, with the possibility of having
// infinity as the result (timeout == 0).
func logLazyTimeout(timeout time.Duration) log15.Lazy {
return log15.Lazy{func() string {
if timeout == 0 {
return "infinity"
}
return fmt.Sprintf("%v", timeout)
}}
}