Git Product home page Git Product logo

log4go's Introduction

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

log4go's People

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

xf005

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.