Go language (log4go introduction)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Today, we introduce a third-party package that is commonly used in the go language, that is, log4go. In C + +, there are log4cpp, and in Java, there are log4j.

Well, don't say much nonsense, now to introduce the use of Log4go. The links on Log4go on GitHub are as follows

Links: Https://github.com/skoo87/log4go

You can refer to the examples folder for specific usage , and the configuration file is in JSON format. A typical example is the following

Log.json:

{    "LogLevel": "Info",    "FileWriter": {        "LogPath": "Log-%y%m%d.log",        "on": True    },    " Consolewriter ": {        " on ": True    }}


Main.go:

Package Mainimport (log "Github.com/skoo87/log4go") func main () {if err: = log. Setuplogwithconf (".. /src/conf/log.json "); Err! = Nil {panic (err)}defer log. Close () var name = "Skoo" log. Debug ("Log4go by%s", name) log. Info ("Log4go by%s", name) log. Warn ("Log4go by%s", name) log. Error ("Log4go by%s", name) log. Fatal ("Log4go by%s", name)}

The new project is structured as follows

Compile in src directory, as follows

Then in the project root directory Log4go get the Bin folder, which has an executable file, execute this file, as follows

At the same time also got the log output file, the following structure

Well, if you want to refer to log4go more, the examples folder has a lot, the path is as follows

Examples path:log4go/src/github.com/skoo87/log4go/examples

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.