Simple usage of Golang log--seelog

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

Beego's own log package, although more complete, but in the log with a log-level timestamp, and this timestamp is not deleted.

Because the project needs, so study the next Golang in the other log packages, found that seelog just can meet our project needs, so in this brief introduction.

Seelog's address: "Github.com/cihub/seelog"

Seelog is a powerful, simple introduction to saving the log configuration in an XML file, and getting the configuration from the file and then using the process.

In a file in the controllers package:

Mainlog, _ = Seelog. Loggerfromconfigasfile ("Conf/seelog-main.xml")
Loggerfromconfigasfile will get the log configuration from the later files, as above is the configuration from the Seelog-main.xml file of the Conf package;

The contents of the Seelog-main.xml file are as follows:

<seelog><outputs formatid= "main" ><buffered size= "10000" flushperiod= "+" ><rollingfile type= "Date" filename= "/var/log/main.log" datepattern= "2006.01.02" maxrolls= "$"/></buffered></outputs> <formats>        <format id= "main" format= "%msg%n"/>    </formats></seelog>

which

Outputs inside is the log configuration, formats inside is the log output format configuration.

The FormatID corresponds to the output format of the corresponding ID in the formats below.

Buffered refers to the buffer setting:

size--buffer size, unit byte;flushperiod--buffer interval, unit ms

Rollingfile inside is the log settings:

type--rollback, date refers to roll-by-date, size is a rollback

filename--file path

datepattern--date format, this option is only available when rolling back by date

maxrolls--the maximum age at which logs are saved, where logs are kept for less than 30 days

Format inside:

id--corresponding to the FormatID of outputs

format--the format of the log output,%msg%n indicates that only the log is output and the line is wrapped

When used, the following:

Defer Mainlog. Flush () Mainlog. Info ("Log Required for entry")
Can. Will improve the use of seelog in the future


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.