logger

package module
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2021 License: MIT Imports: 9 Imported by: 0

README

log4go

Go log module based on Uber's zap and lumberjack

中文文档

Install
go get -u github.com/wanghuiyt/log4go
Usage

example.go

package main

import "github.com/wanghuiyt/log4go"

func main() {
    logger.Info("This is a message")
    logger.Infow("failed to fetch URL",
        "url", "example.com",
        "attempt", 3,
        "backoff", 1,
    )
    logger.Warn("This is a warning message")
    logger.Error("This is an error message")
}

example file structure:

exampleProject
├─util
│    xx1.go
│    xx2.go
│
│ main.go
│ log4go.yml  # The configuration file named `log4go.yml` must exist
Configuration

Make sure log4go.yml exists in the project directory, If it doesn't exist, the program will throw an exception The system cannot find the file specified.

The value of the configuration file is not case sensitive.

This is the explanation of the configuration:

log4go.yml

LOG4GO:
    # Log record format, can be text mode or Json.
    # The value can only be `Text` or `Json`.
    FORMAT: Json
    # If it is `contain`, the error information will also be included in the info file.
    # The value can only be `contain` or `independent`.
    LEVEL_MODE: independent
    # If true, the color of the level is displayed in the file.
    # The value can only be `true` or `false`.
    LEVEL_COLOR: true
    INFO:
        # File path with level greater than INFO. 
        # If LEVEL_MODE is `independent`, this file only records INFO and WARN logs.
        # example: /var/log/info.log
        FILE_PATH_NAME: info.log
        # The maximum size in megabytes of the log file before it gets rotated.
        MAXSIZE: 50
        # The maximum number of old log files to retain.
        MAXBACKUP_COUNT: 10
        # The maximum number of days to retain old log files based on the timestamp encoded in their filename.
        MAXAGE: 28
        # Determines if the rotated log files should be compressed using gzip.
        COMPRESS: true
    ERROR:
        # The file path with a level greater than or equal to ERROR.
        FILE_PATH_NAME: error.log
        MAXSIZE: 50
        MAXBACKUP_COUNT: 10
        MAXAGE: 28
        COMPRESS: true

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger *zap.Logger

Functions

func Error

func Error(args ...interface{})

func Errorf

func Errorf(temp string, args ...interface{})

func Errorw

func Errorw(msg string, keysAndValues ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(temp string, args ...interface{})

func Fatalw

func Fatalw(msg string, keysAndValues ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(temp string, args ...interface{})

func Infow

func Infow(msg string, keysAndValues ...interface{})

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(temp string, args ...interface{})

func Warnw

func Warnw(msg string, keysAndValues ...interface{})

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL