You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

515 lines
8.1 KiB

3 years ago
package field
import (
"fmt"
"time"
)
func Any(key string, value any) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func String(key, value string) Field {
return Field{
Key: key,
Value: StringValue(value),
}
3 years ago
}
func Stringp(key string, value *string) Field {
return Field{
Key: key,
Value: StringpValue(value),
}
3 years ago
}
func Strings(key string, value ...string) Field {
return Field{
Key: key,
Value: StringsValue(value),
}
3 years ago
}
func Bool(key string, value bool) Field {
return Field{
Key: key,
Value: BoolValue(value),
}
3 years ago
}
func Bools(key string, value ...bool) Field {
return Field{
Key: key,
Value: BoolsValue(value),
}
3 years ago
}
func Boolp(key string, value *bool) Field {
return Field{
Key: key,
Value: BoolpValue(value),
}
3 years ago
}
func Uint(key string, value uint) Field {
return Field{
Key: key,
Value: Uint64Value(uint64(value)),
}
3 years ago
}
func Uints(key string, value ...uint) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Uintp(key string, value *uint) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Uint8(key string, value uint8) Field {
return Field{
Key: key,
Value: Uint64Value(uint64(value)),
}
3 years ago
}
func Uint8s(key string, value ...uint8) Field {
return Field{
Key: key,
Value: Uint8sValue(value),
}
3 years ago
}
func Uint8p(key string, value *uint8) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Uint16(key string, value uint16) Field {
return Field{
Key: key,
Value: Uint64Value(uint64(value)),
}
3 years ago
}
func Uint16s(key string, value ...uint16) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Uint16p(key string, value *uint16) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Uint32(key string, value uint32) Field {
return Field{
Key: key,
Value: Uint64Value(uint64(value)),
}
3 years ago
}
func Uint32s(key string, value ...uint32) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Uint32p(key string, value *uint32) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Uint64(key string, value uint64) Field {
return Field{
Key: key,
Value: Uint64Value(value),
}
3 years ago
}
func Uint64s(key string, value ...uint64) Field {
return Field{
Key: key,
Value: Uint64sValue(value),
}
3 years ago
}
func Uint64p(key string, value *uint64) Field {
return Field{
Key: key,
Value: Uint64pValue(value),
}
3 years ago
}
func Int(key string, value int) Field {
return Field{
Key: key,
Value: Int64Value(int64(value)),
}
3 years ago
}
func Ints(key string, value ...int) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Intp(key string, value *int) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Int8(key string, value int8) Field {
return Field{
Key: key,
Value: Int64Value(int64(value)),
}
3 years ago
}
func Int8s(key string, value ...int8) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Int8p(key string, value *int8) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Int16(key string, value int16) Field {
return Field{
Key: key,
Value: Int64Value(int64(value)),
}
3 years ago
}
func Int16s(key string, value ...int16) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Int16p(key string, value *int16) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Int32(key string, value int32) Field {
return Field{
Key: key,
Value: Int64Value(int64(value)),
}
3 years ago
}
func Int32s(key string, value ...int32) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Int32p(key string, value *int32) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Int64(key string, value int64) Field {
return Field{
Key: key,
Value: Int64Value(value),
}
3 years ago
}
func Int64s(key string, value ...int64) Field {
return Field{
Key: key,
Value: Int64sValue(value),
}
3 years ago
}
func Int64p(key string, value *int64) Field {
return Field{
Key: key,
Value: Int64pValue(value),
}
3 years ago
}
func Float32(key string, value float32) Field {
return Field{
Key: key,
Value: Float64Value(float64(value)),
}
3 years ago
}
func Float32s(key string, value ...float32) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Float32p(key string, value *float32) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Float64(key string, value float64) Field {
return Field{
Key: key,
Value: Float64Value(value),
}
3 years ago
}
func Float64s(key string, value ...float64) Field {
return Field{
Key: key,
Value: Float64sValue(value),
}
3 years ago
}
func Float64p(key string, value *float64) Field {
return Field{
Key: key,
Value: Float64pValue(value),
}
3 years ago
}
func Complex64(key string, value complex64) Field {
return Field{
Key: key,
Value: Complex128Value(complex128(value)),
}
3 years ago
}
func Complex64s(key string, value ...complex64) Field {
return Field{
Key: key,
Value: Complex64sValue(value),
}
3 years ago
}
func Complex64p(key string, value *complex64) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
}
func Complex128(key string, value complex128) Field {
return Field{
Key: key,
Value: Complex128Value(value),
}
}
func Complex128s(key string, value ...complex128) Field {
return Field{
Key: key,
Value: Complex128sValue(value),
}
}
func Complex128p(key string, value *complex128) Field {
return Field{
Key: key,
Value: Complex128pValue(value),
}
3 years ago
}
func Uintptr(key string, value uintptr) Field {
return Field{
Key: key,
Value: Uint64Value(uint64(value)),
}
3 years ago
}
func Uintptrs(key string, value ...uintptr) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Uintptrp(key string, value *uintptr) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
3 years ago
}
func Bytes(key string, value []byte) Field {
return Field{
Key: key,
Value: BytesValue(value),
}
3 years ago
}
func Duration(key string, value time.Duration) Field {
return Field{
Key: key,
Value: DurationValue(value),
}
3 years ago
}
func Durations(key string, value ...time.Duration) Field {
return Field{
Key: key,
Value: DurationsValue(value),
}
3 years ago
}
func Durationp(key string, value *time.Duration) Field {
return Field{
Key: key,
Value: DurationpValue(value),
}
3 years ago
}
func Time(key string, value time.Time) Field {
return Field{
Key: key,
Value: TimeValue(value),
}
3 years ago
}
func Times(key string, value ...time.Time) Field {
return Field{
Key: key,
Value: TimesValue(value),
}
3 years ago
}
func Timep(key string, value *time.Time) Field {
return Field{
Key: key,
Value: TimepValue(value),
}
3 years ago
}
func FormatTime(key, format string, value time.Time) Field {
return Field{
Key: key,
Value: ClosureValue(func() any {
return value.Format(format)
}),
}
3 years ago
}
func FormatTimes(key, format string, value ...time.Time) Field {
return Field{
Key: key,
Value: ClosureValue(func() any {
times := make([]any, len(value))
for idx, val := range value {
times[idx] = val.Format(format)
}
return times
}),
}
3 years ago
}
func FormatTimep(key, format string, value *time.Time) Field {
isNill := value == nil
return Field{
Key: key,
Value: ClosureValue(func() any {
if isNill {
return NilValue()
}
return value.Format(format)
}),
}
3 years ago
}
func Error(key string, value error) Field {
return Field{
Key: key,
Value: ErrorValue(value),
}
3 years ago
}
func Errors(key string, value ...error) Field {
return Field{
Key: key,
Value: ErrorsValue(value),
}
}
func Groups(key string, value ...Field) Field {
return Field{
Key: key,
Value: GroupValue(value...),
}
}
func Valuer(key string, value LogValuer) Field {
return Field{
Key: key,
Value: AnyValue(value),
}
}
func ValuerFn(key string, value ClosureFn) Field {
return Field{
Key: key,
Value: ClosureValue(value),
}
3 years ago
}
// Field struct.
type Field struct {
Key string
Value Value
3 years ago
}
// String implent stringer.
func (f Field) String() string {
return fmt.Sprintf("%s=%+v", f.Key, f.Value)
3 years ago
}
// String implent stringer.
func (f Field) IsKey(keys ...string) bool {
for _, key := range keys {
if key == f.Key {
return true
}
}
return false
}