package
1.12.6
Repository: https://github.com/go-dev-frame/sponge.git
Documentation: pkg.go.dev

# README

logger

Logger library wrapped in zap.

  • Support for terminal printing and log saving.
  • Support for automatic log file cutting.
  • Support for json format and console log format output.
  • Support Debug, Info, Warn, Error, Panic, Fatal, also supports fmt.Printf-like log printing, Debugf, Infof, Warnf, Errorf, Panicf, Fatalf.

Example of use

    import "github.com/go-dev-frame/sponge/pkg/logger"

    // (1) used directly, it will be initialised by default
    logger.Info("this is info")
    logger.Warn("this is warn", logger.String("foo","bar"), logger.Int("size",10), logger.Any("obj",obj))
    logger.Error("this is error", logger.Err(err), logger.String("foo","bar"))

    // (2) Initialize and then use
    logger.Init(
        logger.WithLevel("info"),     // set the data logging level, the default is debug
        logger.WithFormat("json"),  // set output format, default console
        logger.WithSave(true,         // set whether to save the log locally, default false
        //    logger.WithFileName("my.log"),      // file name, default is "out.log"
        //    logger.WithFileMaxSize(5),              // maximum file size (MB), default 10
       //     logger.WithFileMaxBackups(5),        // maximum number of old files, default 100
       //     logger.WithFileMaxAge(10),             // maximum number of days for old documents, default 30
       //     logger.WithFileIsCompression(true), // whether to compress and archive old files, default false
        )
    )
    logger.Info("this is info")
    logger.Warn("this is warn", logger.String("foo","bar"), logger.Int("size",10), logger.Any("obj",obj))
    logger.Error("this is error", logger.Err(err), logger.String("foo","bar"))

// (3) with hooks
    logger.Init(
        logger.WithLevel("info"),
        logger.WithHooks(func(entry zapcore.Entry) error {
            if strings.Contains(entry.Message, "error") {
                fmt.Println("it contains error message")
            }
            return nil
        }),
    )
    logger.Error("this is error", logger.Err(err), logger.String("foo","bar"))

# Functions

Any type, if it is a composite type such as object, slice, map, etc., use Any.
Bool type.
ByteString type.
Debug level information.
Debugf format level information.
Duration type.
Err type.
Error level information.
Errorf format level information.
Fatal level information.
Fatalf format level information.
Float64 type.
Get logger.
GetWithSkip get defaultLogger, set the skipped caller value, customize the number of lines of code displayed.
Info level information.
Infof format level information.
Init initial log settings print the debug level log in the terminal, example: Init() print the info level log in the terminal, example: Init(WithLevel("info")) print the json format, debug level log in the terminal, example: Init(WithFormat("json")) log with hooks, example: Init(WithHooks(func(zapcore.Entry) error{return nil})) output the log to the file out.log, using the default cut log-related parameters, debug-level log, example: Init(WithSave()) output the log to the specified file, custom set the log file cut log parameters, json format, debug level log, example: Init( WithFormat("json"), WithSave(true, WithFileName("my.log"), WithFileMaxSize(5), WithFileMaxBackups(5), WithFileMaxAge(10), WithFileIsCompression(true), )).
Int type.
Int32 type.
Int64 type.
Panic level information.
ReplaceGRPCLoggerV2 replace grpc logger v2.
String type.
Stringer type.
Sync flushing any buffered log entries, applications should take care to call Sync before exiting.
Time type.
Uint type.
Uint32 type.
Uint64 type.
Uintptr type.
Warn level information.
Warnf format level information.
WithFields carrying field information.
WithFileIsCompression set whether to compress log files.
WithFileMaxAge set maximum number of days for old documents.
WithFileMaxBackups set maximum number of old files.
WithFileMaxSize set maximum file size (MB).
WithFileName set log filename.
WithFormat set the output log format, console or json.
WithHooks set the log hooks.
WithLevel setting the log level.
WithLocalTime set whether to use local time.
WithSave save log to file.

# Type aliases

Field type.
FileOption set the file options.
Option set the logger options.