// Copyright (c) 2016 Uber Technologies, Inc.1//2// Permission is hereby granted, free of charge, to any person obtaining a copy3// of this software and associated documentation files (the "Software"), to deal4// in the Software without restriction, including without limitation the rights5// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell6// copies of the Software, and to permit persons to whom the Software is7// furnished to do so, subject to the following conditions:8//9// The above copyright notice and this permission notice shall be included in10// all copies or substantial portions of the Software.11//12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR13// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,14// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE15// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER16// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,17// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN18// THE SOFTWARE.1920// Package zap provides fast, structured, leveled logging.21//22// For applications that log in the hot path, reflection-based serialization23// and string formatting are prohibitively expensive - they're CPU-intensive24// and make many small allocations. Put differently, using json.Marshal and25// fmt.Fprintf to log tons of interface{} makes your application slow.26//27// Zap takes a different approach. It includes a reflection-free,28// zero-allocation JSON encoder, and the base Logger strives to avoid29// serialization overhead and allocations wherever possible. By building the30// high-level SugaredLogger on that foundation, zap lets users choose when31// they need to count every allocation and when they'd prefer a more familiar,32// loosely typed API.33//34// # Choosing a Logger35//36// In contexts where performance is nice, but not critical, use the37// SugaredLogger. It's 4-10x faster than other structured logging packages and38// supports both structured and printf-style logging. Like log15 and go-kit,39// the SugaredLogger's structured logging APIs are loosely typed and accept a40// variadic number of key-value pairs. (For more advanced use cases, they also41// accept strongly typed fields - see the SugaredLogger.With documentation for42// details.)43//44// sugar := zap.NewExample().Sugar()45// defer sugar.Sync()46// sugar.Infow("failed to fetch URL",47// "url", "http://example.com",48// "attempt", 3,49// "backoff", time.Second,50// )51// sugar.Infof("failed to fetch URL: %s", "http://example.com")52//53// By default, loggers are unbuffered. However, since zap's low-level APIs54// allow buffering, calling Sync before letting your process exit is a good55// habit.56//57// In the rare contexts where every microsecond and every allocation matter,58// use the Logger. It's even faster than the SugaredLogger and allocates far59// less, but it only supports strongly-typed, structured logging.60//61// logger := zap.NewExample()62// defer logger.Sync()63// logger.Info("failed to fetch URL",64// zap.String("url", "http://example.com"),65// zap.Int("attempt", 3),66// zap.Duration("backoff", time.Second),67// )68//69// Choosing between the Logger and SugaredLogger doesn't need to be an70// application-wide decision: converting between the two is simple and71// inexpensive.72//73// logger := zap.NewExample()74// defer logger.Sync()75// sugar := logger.Sugar()76// plain := sugar.Desugar()77//78// # Configuring Zap79//80// The simplest way to build a Logger is to use zap's opinionated presets:81// NewExample, NewProduction, and NewDevelopment. These presets build a logger82// with a single function call:83//84// logger, err := zap.NewProduction()85// if err != nil {86// log.Fatalf("can't initialize zap logger: %v", err)87// }88// defer logger.Sync()89//90// Presets are fine for small projects, but larger projects and organizations91// naturally require a bit more customization. For most users, zap's Config92// struct strikes the right balance between flexibility and convenience. See93// the package-level BasicConfiguration example for sample code.94//95// More unusual configurations (splitting output between files, sending logs96// to a message queue, etc.) are possible, but require direct use of97// go.uber.org/zap/zapcore. See the package-level AdvancedConfiguration98// example for sample code.99//100// # Extending Zap101//102// The zap package itself is a relatively thin wrapper around the interfaces103// in go.uber.org/zap/zapcore. Extending zap to support a new encoding (e.g.,104// BSON), a new log sink (e.g., Kafka), or something more exotic (perhaps an105// exception aggregation service, like Sentry or Rollbar) typically requires106// implementing the zapcore.Encoder, zapcore.WriteSyncer, or zapcore.Core107// interfaces. See the zapcore documentation for details.108//109// Similarly, package authors can use the high-performance Encoder and Core110// implementations in the zapcore package to build their own loggers.111//112// # Frequently Asked Questions113//114// An FAQ covering everything from installation errors to design decisions is115// available at https://github.com/uber-go/zap/blob/master/FAQ.md.116package zap // import "go.uber.org/zap"117118119