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