<|start_filename|>sugar.go<|end_filename|>
package sugar

// Debug package mainLogger
func Debug(args ...interface{}) {
	mainLogger.zapSugar.Debug(args...)
}

// Debugf package mainLogger
func Debugf(template string, args ...interface{}) {
	mainLogger.zapSugar.Debugf(template, args...)
}

// Info package mainLogger
func Info(args ...interface{}) {
	mainLogger.zapSugar.Info(args...)
}

// Infof package mainLogger
func Infof(template string, args ...interface{}) {
	mainLogger.zapSugar.Infof(template, args...)
}

// Warn package mainLogger
func Warn(args ...interface{}) {
	mainLogger.zapSugar.Warn(args...)
}

// Warnf package mainLogger
func Warnf(template string, args ...interface{}) {
	mainLogger.zapSugar.Warnf(template, args...)
}

// Error package mainLogger
func Error(args ...interface{}) {
	mainLogger.zapSugar.Error(args...)
}

// Errorf package mainLogger
func Errorf(template string, args ...interface{}) {
	mainLogger.zapSugar.Errorf(template, args...)
}

// Fatal package mainLogger
func Fatal(args ...interface{}) {
	mainLogger.zapSugar.Fatal(args...)
}

// Fatalf package mainLogger
func Fatalf(template string, args ...interface{}) {
	mainLogger.zapSugar.Fatalf(template, args...)
}

// Panic package mainLogger
func Panic(args ...interface{}) {
	mainLogger.zapSugar.Panic(args...)
}

// Panicf package mainLogger
func Panicf(template string, args ...interface{}) {
	mainLogger.zapSugar.Panicf(template, args...)
}


<|start_filename|>examples/default/main.go<|end_filename|>
package main

import "github.com/chalvern/sugar"

func main() {

	sugar.Debug("default development sugar of chalvern")
	myCustomLogger()
	myCustomLogger2()

	sugar.InitProductionSugar()
	sugar.Debug("should not be printed")
	sugar.Info("default production sugar of chalvern")
	myCustomLogger()
	myCustomLogger2()
}

func myCustomLogger() {
	myLogger := sugar.NewLoggerOf("my_custom_logger")
	myLogger.Info("log of myCustomLogger info")
	myLogger.Warn("log of myCustomLogger warn")
}

func myCustomLogger2() {
	myLogger := sugar.NewLoggerOf("my_custom_logger_2")
	myLogger.Info("log of myCustomLogger2 info")
	myLogger.Warn("log of myCustomLogger2 warn")
}


<|start_filename|>init.go<|end_filename|>
package sugar

import (
	"go.uber.org/zap"
)

var (
	zapLogger *zap.Logger
	zapSugar  *zap.SugaredLogger
	// mainLogger default logger, with unit filed valued "main"
	mainLogger *Logger
)

// GetZapLogger get zap's logger for special using
func GetZapLogger() *zap.Logger {
	return zapLogger
}

func init() {
	config := zap.NewDevelopmentConfig()
	config.OutputPaths = []string{"stderr"}
	config.ErrorOutputPaths = []string{"stderr"}
	SetSugar(&config)
}

// InitProductionSugar for production
func InitProductionSugar(opts ...zap.Option) {
	config := zap.NewProductionConfig()
	config.OutputPaths = []string{"stderr"}
	config.ErrorOutputPaths = []string{"stderr"}
	SetSugar(&config, opts...)
}

// InitDevelopmentSugar for development
// encoding being json instead of console,
// which is practically better for docker's json logger,
func InitDevelopmentSugar(opts ...zap.Option) {
	config := zap.NewDevelopmentConfig()
	config.Encoding = "json"
	config.OutputPaths = []string{"stderr"}
	config.ErrorOutputPaths = []string{"stderr"}
	SetSugar(&config, opts...)
}

// SetSugar set sugar's logger
func SetSugar(config *zap.Config, opts ...zap.Option) {
	opts = append(opts, zap.AddCallerSkip(1))
	var err error
	zapLogger, err = config.Build(opts...)
	if err != nil {
		panic(err)
	}
	zapSugar = zapLogger.Sugar()
	mainLogger = NewLoggerOf("main")
}


<|start_filename|>examples/custom/main.go<|end_filename|>
package main

import (
	"github.com/chalvern/sugar"
	"go.uber.org/zap"
)

func main() {
	config := zap.NewProductionConfig()
	config.OutputPaths = []string{"./production.log"}
	config.ErrorOutputPaths = []string{"./production_err.log"}
	sugar.SetSugar(&config)

	sugar.Info("main info")

	myCustomLogger()
}

func myCustomLogger() {
	myLogger := sugar.NewLoggerOf("my_custom_logger")
	myLogger.Info("log of myCustomLogger info")
	myLogger.Warn("log of myCustomLogger warn")
}
