package loggerimport ()var ( logger *zap.Logger)/*Init LoggerCreates log file if does not exist and configures Zap logger*/func () {// TODO: Implement lumberjack log roller // https://gist.github.com/rnyrnyrny/a6dc926ae11951b753ecd66c00695397 := zap.NewProductionConfig() , := strconv.ParseBool(helpers.Env("APP_DEBUG", "false"))if != nil {panic() } .DisableStacktrace = .OutputPaths = []string{"stdout","/liman/logs/liman_new.log", }logger, = .Build()if != nil {log.Fatalf("can't initialize zap logger: %v", ) }}typeZapperinterface {Infow(msg string, keysAndValues ...interface{})Errorw(msg string, keysAndValues ...interface{})Warnw(msg string, keysAndValues ...interface{})}func () *zap.Logger {returnlogger}// A Logger provides fast, leveled, structured logging. All methods are safe for concurrent use.func () *zap.Logger {returnlogger.WithOptions(zap.AddCallerSkip(1))}// Sugar wraps the Logger to provide a more ergonomic, but slightly slower, API. Sugaring a Logger is quite inexpensive,// so it's reasonable for a single application to use both Loggers and SugaredLoggers,// converting between them on the boundaries of performance-sensitive code.func () *zap.SugaredLogger {returnlogger.Sugar().WithOptions(zap.AddCallerSkip(1))}// This method wraps Zap sugared logger with fiber errorsfunc ( int, string) *fiber.Error {switch {case >= 500:Sugar().Errorw( ,"code", , )case >= 400:Sugar().Warnw( ,"code", , )default:Sugar().Infow( ,"code", , ) }returnfiber.NewError(, )}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.