2017-05-15 18:16:13 +00:00
|
|
|
package zerolog
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
import "sync/atomic"
|
|
|
|
|
|
|
|
var (
|
|
|
|
// TimestampFieldName is the field name used for the timestamp field.
|
|
|
|
TimestampFieldName = "time"
|
|
|
|
|
|
|
|
// LevelFieldName is the field name used for the level field.
|
|
|
|
LevelFieldName = "level"
|
|
|
|
|
|
|
|
// MessageFieldName is the field name used for the message field.
|
|
|
|
MessageFieldName = "message"
|
|
|
|
|
|
|
|
// ErrorFieldName is the field name used for error fields.
|
|
|
|
ErrorFieldName = "error"
|
|
|
|
|
2018-02-07 21:54:26 +00:00
|
|
|
// CallerFieldName is the field name used for caller field.
|
|
|
|
CallerFieldName = "caller"
|
|
|
|
|
2018-02-08 05:55:53 +00:00
|
|
|
// ErrorStackFieldName is the field name used for error stacks.
|
|
|
|
ErrorStackFieldName = "stack"
|
|
|
|
|
|
|
|
// ErrorStackMarshaler extract the stack from err if any, and returns it as
|
|
|
|
// a marshaled JSON.
|
|
|
|
ErrorStackMarshaler func(err error) []byte
|
|
|
|
|
2017-05-15 18:16:13 +00:00
|
|
|
// TimeFieldFormat defines the time format of the Time field type.
|
2017-05-20 05:14:51 +00:00
|
|
|
// If set to an empty string, the time is formatted as an UNIX timestamp
|
|
|
|
// as integer.
|
2017-05-15 18:16:13 +00:00
|
|
|
TimeFieldFormat = time.RFC3339
|
2017-05-20 09:22:57 +00:00
|
|
|
|
|
|
|
// TimestampFunc defines the function called to generate a timestamp.
|
|
|
|
TimestampFunc = time.Now
|
2017-05-21 04:08:42 +00:00
|
|
|
|
|
|
|
// DurationFieldUnit defines the unit for time.Duration type fields added
|
|
|
|
// using the Dur method.
|
|
|
|
DurationFieldUnit = time.Millisecond
|
|
|
|
|
|
|
|
// DurationFieldInteger renders Dur fields as integer instead of float if
|
|
|
|
// set to true.
|
|
|
|
DurationFieldInteger = false
|
2017-05-15 18:16:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
gLevel = new(uint32)
|
|
|
|
disableSampling = new(uint32)
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetGlobalLevel sets the global override for log level. If this
|
|
|
|
// values is raised, all Loggers will use at least this value.
|
|
|
|
//
|
|
|
|
// To globally disable logs, set GlobalLevel to Disabled.
|
|
|
|
func SetGlobalLevel(l Level) {
|
|
|
|
atomic.StoreUint32(gLevel, uint32(l))
|
|
|
|
}
|
|
|
|
|
|
|
|
func globalLevel() Level {
|
|
|
|
return Level(atomic.LoadUint32(gLevel))
|
|
|
|
}
|
|
|
|
|
|
|
|
// DisableSampling will disable sampling in all Loggers if true.
|
|
|
|
func DisableSampling(v bool) {
|
|
|
|
var i uint32
|
|
|
|
if v {
|
|
|
|
i = 1
|
|
|
|
}
|
|
|
|
atomic.StoreUint32(disableSampling, i)
|
|
|
|
}
|
|
|
|
|
|
|
|
func samplingDisabled() bool {
|
2017-06-30 14:53:27 +00:00
|
|
|
return atomic.LoadUint32(disableSampling) == 1
|
2017-05-15 18:16:13 +00:00
|
|
|
}
|