"Golang" Go language learning-logger

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

Go-logger is the Golang log library, based on the Golang built-in log package.
Usage similar to the Java Journaling Toolkit log4j

Print Log has 5 methods Debug,info,warn, Error, Fatal log level from low to high

The method for setting the log level is: Logger. SetLevel () such as: Logger. SetLevel (logger. WARN)
Then: Logger. Debug (...), logger. The Info (...) log is not typed and
Logger. Warn (...), logger. Error (...), logger. Fatal (...) The log will be typed.
There are 7 parameters for setting the log level, namely: All,debug,info,warn,error,fatal,off
Where all means all methods that call the print log are typed, and off means they are not typed.

There are two types of log file cuts: 1 is segmented by date. 2 is segmented by log size.
When slicing by date: One backup log file per day, with a suffix of. yyyy-mm-dd
Over 0 points is generated the day before the backup file

Slicing by size requires 3 parameters, 1 for file size, 2 for units, and 3 for number of files
When the file grows to a specified limit, the backup file is generated, ending with a natural number that increments in sequence.
When the number of files increases to the specified limit, the newly generated log file overwrites the previously generated backup log file with the same name.

Specifies whether the console prints, by default, True
Logger. Setconsole (True)
Specify how log files are backed up as file sizes
The first parameter holds the directory for the log file
The second parameter is a log file name
The third parameter is the maximum number of backup files
The fourth parameter is the backup file size
The fifth parameter is the file size unit KB,MB,GB, TB
Logger. Setrollingfile ("D:/logtest", "Test.log", ten, 5, logger. KB)

Specify how log files are backed up as a date
The first parameter holds the directory for the log file
The second parameter is a log file name
Logger. Setrollingdaily ("D:/logtest", "Test.log")

Specify log level All,debug,info,warn,error,fatal,off level from low to high
The general habit is that the test phase is debug and the build environment is more than info
Logger. SetLevel (logger. DEBUG)

Print log:
Func log (i int) {
Logger. Debug ("debug>>>>>>>>>>>>>>>>>>>>>>" + StrConv. Itoa (i))
Logger. Info ("info>>>>>>>>>>>>>>>>>>>>>>>>> "+ StrConv. Itoa (i))
Logger. Warn ("warn>>>>>>>>>>>>>>>>>>>>>>>>> "+ StrConv. Itoa (i))
Logger. Error ("error>>>>>>>>>>>>>>>>>>>>>>>> > "+ StrConv. Itoa (i))
Logger. Fatal ("fatal>>>>>>>>>>>>>>>>>>>>>>>> > "+ StrConv. Itoa (i))


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.