// Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package zap

import (
	
	
	

	
)

// Field is an alias for Field. Aliasing this type dramatically
// improves the navigability of this package's API documentation.
type Field = zapcore.Field

var (
	_minTimeInt64 = time.Unix(0, math.MinInt64)
	_maxTimeInt64 = time.Unix(0, math.MaxInt64)
)

// Skip constructs a no-op field, which is often useful when handling invalid
// inputs in other Field constructors.
func () Field {
	return Field{Type: zapcore.SkipType}
}

// nilField returns a field which will marshal explicitly as nil. See motivation
// in https://github.com/uber-go/zap/issues/753 . If we ever make breaking
// changes and add zapcore.NilType and zapcore.ObjectEncoder.AddNil, the
// implementation here should be changed to reflect that.
func ( string) Field { return Reflect(, nil) }

// Binary constructs a field that carries an opaque binary blob.
//
// Binary data is serialized in an encoding-appropriate format. For example,
// zap's JSON encoder base64-encodes binary blobs. To log UTF-8 encoded text,
// use ByteString.
func ( string,  []byte) Field {
	return Field{Key: , Type: zapcore.BinaryType, Interface: }
}

// Bool constructs a field that carries a bool.
func ( string,  bool) Field {
	var  int64
	if  {
		 = 1
	}
	return Field{Key: , Type: zapcore.BoolType, Integer: }
}

// Boolp constructs a field that carries a *bool. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *bool) Field {
	if  == nil {
		return nilField()
	}
	return Bool(, *)
}

// ByteString constructs a field that carries UTF-8 encoded text as a []byte.
// To log opaque binary blobs (which aren't necessarily valid UTF-8), use
// Binary.
func ( string,  []byte) Field {
	return Field{Key: , Type: zapcore.ByteStringType, Interface: }
}

// Complex128 constructs a field that carries a complex number. Unlike most
// numeric fields, this costs an allocation (to convert the complex128 to
// interface{}).
func ( string,  complex128) Field {
	return Field{Key: , Type: zapcore.Complex128Type, Interface: }
}

// Complex128p constructs a field that carries a *complex128. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *complex128) Field {
	if  == nil {
		return nilField()
	}
	return Complex128(, *)
}

// Complex64 constructs a field that carries a complex number. Unlike most
// numeric fields, this costs an allocation (to convert the complex64 to
// interface{}).
func ( string,  complex64) Field {
	return Field{Key: , Type: zapcore.Complex64Type, Interface: }
}

// Complex64p constructs a field that carries a *complex64. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *complex64) Field {
	if  == nil {
		return nilField()
	}
	return Complex64(, *)
}

// Float64 constructs a field that carries a float64. The way the
// floating-point value is represented is encoder-dependent, so marshaling is
// necessarily lazy.
func ( string,  float64) Field {
	return Field{Key: , Type: zapcore.Float64Type, Integer: int64(math.Float64bits())}
}

// Float64p constructs a field that carries a *float64. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *float64) Field {
	if  == nil {
		return nilField()
	}
	return Float64(, *)
}

// Float32 constructs a field that carries a float32. The way the
// floating-point value is represented is encoder-dependent, so marshaling is
// necessarily lazy.
func ( string,  float32) Field {
	return Field{Key: , Type: zapcore.Float32Type, Integer: int64(math.Float32bits())}
}

// Float32p constructs a field that carries a *float32. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *float32) Field {
	if  == nil {
		return nilField()
	}
	return Float32(, *)
}

// Int constructs a field with the given key and value.
func ( string,  int) Field {
	return Int64(, int64())
}

// Intp constructs a field that carries a *int. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *int) Field {
	if  == nil {
		return nilField()
	}
	return Int(, *)
}

// Int64 constructs a field with the given key and value.
func ( string,  int64) Field {
	return Field{Key: , Type: zapcore.Int64Type, Integer: }
}

// Int64p constructs a field that carries a *int64. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *int64) Field {
	if  == nil {
		return nilField()
	}
	return Int64(, *)
}

// Int32 constructs a field with the given key and value.
func ( string,  int32) Field {
	return Field{Key: , Type: zapcore.Int32Type, Integer: int64()}
}

// Int32p constructs a field that carries a *int32. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *int32) Field {
	if  == nil {
		return nilField()
	}
	return Int32(, *)
}

// Int16 constructs a field with the given key and value.
func ( string,  int16) Field {
	return Field{Key: , Type: zapcore.Int16Type, Integer: int64()}
}

// Int16p constructs a field that carries a *int16. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *int16) Field {
	if  == nil {
		return nilField()
	}
	return Int16(, *)
}

// Int8 constructs a field with the given key and value.
func ( string,  int8) Field {
	return Field{Key: , Type: zapcore.Int8Type, Integer: int64()}
}

// Int8p constructs a field that carries a *int8. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *int8) Field {
	if  == nil {
		return nilField()
	}
	return Int8(, *)
}

// String constructs a field with the given key and value.
func ( string,  string) Field {
	return Field{Key: , Type: zapcore.StringType, String: }
}

// Stringp constructs a field that carries a *string. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *string) Field {
	if  == nil {
		return nilField()
	}
	return String(, *)
}

// Uint constructs a field with the given key and value.
func ( string,  uint) Field {
	return Uint64(, uint64())
}

// Uintp constructs a field that carries a *uint. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *uint) Field {
	if  == nil {
		return nilField()
	}
	return Uint(, *)
}

// Uint64 constructs a field with the given key and value.
func ( string,  uint64) Field {
	return Field{Key: , Type: zapcore.Uint64Type, Integer: int64()}
}

// Uint64p constructs a field that carries a *uint64. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *uint64) Field {
	if  == nil {
		return nilField()
	}
	return Uint64(, *)
}

// Uint32 constructs a field with the given key and value.
func ( string,  uint32) Field {
	return Field{Key: , Type: zapcore.Uint32Type, Integer: int64()}
}

// Uint32p constructs a field that carries a *uint32. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *uint32) Field {
	if  == nil {
		return nilField()
	}
	return Uint32(, *)
}

// Uint16 constructs a field with the given key and value.
func ( string,  uint16) Field {
	return Field{Key: , Type: zapcore.Uint16Type, Integer: int64()}
}

// Uint16p constructs a field that carries a *uint16. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *uint16) Field {
	if  == nil {
		return nilField()
	}
	return Uint16(, *)
}

// Uint8 constructs a field with the given key and value.
func ( string,  uint8) Field {
	return Field{Key: , Type: zapcore.Uint8Type, Integer: int64()}
}

// Uint8p constructs a field that carries a *uint8. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *uint8) Field {
	if  == nil {
		return nilField()
	}
	return Uint8(, *)
}

// Uintptr constructs a field with the given key and value.
func ( string,  uintptr) Field {
	return Field{Key: , Type: zapcore.UintptrType, Integer: int64()}
}

// Uintptrp constructs a field that carries a *uintptr. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *uintptr) Field {
	if  == nil {
		return nilField()
	}
	return Uintptr(, *)
}

// Reflect constructs a field with the given key and an arbitrary object. It uses
// an encoding-appropriate, reflection-based function to lazily serialize nearly
// any object into the logging context, but it's relatively slow and
// allocation-heavy. Outside tests, Any is always a better choice.
//
// If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect
// includes the error message in the final log output.
func ( string,  interface{}) Field {
	return Field{Key: , Type: zapcore.ReflectType, Interface: }
}

// Namespace creates a named, isolated scope within the logger's context. All
// subsequent fields will be added to the new namespace.
//
// This helps prevent key collisions when injecting loggers into sub-components
// or third-party libraries.
func ( string) Field {
	return Field{Key: , Type: zapcore.NamespaceType}
}

// Stringer constructs a field with the given key and the output of the value's
// String method. The Stringer's String method is called lazily.
func ( string,  fmt.Stringer) Field {
	return Field{Key: , Type: zapcore.StringerType, Interface: }
}

// Time constructs a Field with the given key and value. The encoder
// controls how the time is serialized.
func ( string,  time.Time) Field {
	if .Before(_minTimeInt64) || .After(_maxTimeInt64) {
		return Field{Key: , Type: zapcore.TimeFullType, Interface: }
	}
	return Field{Key: , Type: zapcore.TimeType, Integer: .UnixNano(), Interface: .Location()}
}

// Timep constructs a field that carries a *time.Time. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *time.Time) Field {
	if  == nil {
		return nilField()
	}
	return Time(, *)
}

// Stack constructs a field that stores a stacktrace of the current goroutine
// under provided key. Keep in mind that taking a stacktrace is eager and
// expensive (relatively speaking); this function both makes an allocation and
// takes about two microseconds.
func ( string) Field {
	return StackSkip(, 1) // skip Stack
}

// StackSkip constructs a field similarly to Stack, but also skips the given
// number of frames from the top of the stacktrace.
func ( string,  int) Field {
	// Returning the stacktrace as a string costs an allocation, but saves us
	// from expanding the zapcore.Field union struct to include a byte slice. Since
	// taking a stacktrace is already so expensive (~10us), the extra allocation
	// is okay.
	return String(, takeStacktrace(+1)) // skip StackSkip
}

// Duration constructs a field with the given key and value. The encoder
// controls how the duration is serialized.
func ( string,  time.Duration) Field {
	return Field{Key: , Type: zapcore.DurationType, Integer: int64()}
}

// Durationp constructs a field that carries a *time.Duration. The returned Field will safely
// and explicitly represent `nil` when appropriate.
func ( string,  *time.Duration) Field {
	if  == nil {
		return nilField()
	}
	return Duration(, *)
}

// Object constructs a field with the given key and ObjectMarshaler. It
// provides a flexible, but still type-safe and efficient, way to add map- or
// struct-like user-defined types to the logging context. The struct's
// MarshalLogObject method is called lazily.
func ( string,  zapcore.ObjectMarshaler) Field {
	return Field{Key: , Type: zapcore.ObjectMarshalerType, Interface: }
}

// Inline constructs a Field that is similar to Object, but it
// will add the elements of the provided ObjectMarshaler to the
// current namespace.
func ( zapcore.ObjectMarshaler) Field {
	return zapcore.Field{
		Type:      zapcore.InlineMarshalerType,
		Interface: ,
	}
}

// Any takes a key and an arbitrary value and chooses the best way to represent
// them as a field, falling back to a reflection-based approach only if
// necessary.
//
// Since byte/uint8 and rune/int32 are aliases, Any can't differentiate between
// them. To minimize surprises, []byte values are treated as binary blobs, byte
// values are treated as uint8, and runes are always treated as integers.
func ( string,  interface{}) Field {
	switch val := .(type) {
	case zapcore.ObjectMarshaler:
		return Object(, )
	case zapcore.ArrayMarshaler:
		return Array(, )
	case bool:
		return Bool(, )
	case *bool:
		return Boolp(, )
	case []bool:
		return Bools(, )
	case complex128:
		return Complex128(, )
	case *complex128:
		return Complex128p(, )
	case []complex128:
		return Complex128s(, )
	case complex64:
		return Complex64(, )
	case *complex64:
		return Complex64p(, )
	case []complex64:
		return Complex64s(, )
	case float64:
		return Float64(, )
	case *float64:
		return Float64p(, )
	case []float64:
		return Float64s(, )
	case float32:
		return Float32(, )
	case *float32:
		return Float32p(, )
	case []float32:
		return Float32s(, )
	case int:
		return Int(, )
	case *int:
		return Intp(, )
	case []int:
		return Ints(, )
	case int64:
		return Int64(, )
	case *int64:
		return Int64p(, )
	case []int64:
		return Int64s(, )
	case int32:
		return Int32(, )
	case *int32:
		return Int32p(, )
	case []int32:
		return Int32s(, )
	case int16:
		return Int16(, )
	case *int16:
		return Int16p(, )
	case []int16:
		return Int16s(, )
	case int8:
		return Int8(, )
	case *int8:
		return Int8p(, )
	case []int8:
		return Int8s(, )
	case string:
		return String(, )
	case *string:
		return Stringp(, )
	case []string:
		return Strings(, )
	case uint:
		return Uint(, )
	case *uint:
		return Uintp(, )
	case []uint:
		return Uints(, )
	case uint64:
		return Uint64(, )
	case *uint64:
		return Uint64p(, )
	case []uint64:
		return Uint64s(, )
	case uint32:
		return Uint32(, )
	case *uint32:
		return Uint32p(, )
	case []uint32:
		return Uint32s(, )
	case uint16:
		return Uint16(, )
	case *uint16:
		return Uint16p(, )
	case []uint16:
		return Uint16s(, )
	case uint8:
		return Uint8(, )
	case *uint8:
		return Uint8p(, )
	case []byte:
		return Binary(, )
	case uintptr:
		return Uintptr(, )
	case *uintptr:
		return Uintptrp(, )
	case []uintptr:
		return Uintptrs(, )
	case time.Time:
		return Time(, )
	case *time.Time:
		return Timep(, )
	case []time.Time:
		return Times(, )
	case time.Duration:
		return Duration(, )
	case *time.Duration:
		return Durationp(, )
	case []time.Duration:
		return Durations(, )
	case error:
		return NamedError(, )
	case []error:
		return Errors(, )
	case fmt.Stringer:
		return Stringer(, )
	default:
		return Reflect(, )
	}
}