Go language: Log4go

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
Log4go usage of the log framework in the Go language
Package Mainimport (l4g "Github.com/alecthomas/log4go") func main () {l4g. AddFilter ("stdout", l4g. DEBUG, L4G. Newconsolelogwriter ())             //Output to console, level debugl4g.addfilter ("file", l4g. DEBUG, L4G. Newfilelogwriter ("Test.log", false))//output to file, level is debug, file name is Test.log, append the original file//l4g each time. Loadconfiguration ("Log.xml")//Use load Config file, similar to Java log4j.propertitesl4g.Debug ("The Time is now:%s--%s", "213", "sad") Defer L4G. Close ()//NOTE: If you are not running the program, please add this sentence, otherwise the main thread end, will not output and log to the log file}


This will generate a Test.log log file in the current folder of the Go project.

If it is used to load the configuration file, then create a new log4go.xml content below, roughly can understand not much to say.

<logging> <filter enabled= "true" > <tag>stdout</tag> <type>console</type> &lt ;! --Level is (:? Finest| fine| Debug| trace|info| Warning| ERROR)-<level>DEBUG</level> </filter> <filter enabled= "true" > <tag>file</t ag> <type>file</type> <level>FINEST</level> <property name= "filename" >test.log&l T;/property> <!--%t-time (15:04:05 MST)%t-time (15:04)%d-date (2006/01/02)%d- Date (01/02/06)%l-level (Fnst, FINE, DEBG, TRAC, WARN, Eror, crit)%s-source%m-message It ignores unknown format strings (and removes them) Recommended: "[%d%T] [%l] (%s)%M"-<property name = "format" >[%d%T] [%l] (%s)%m</property> <property name= "Rotate" >false</property> <!--true en Ables log rotation, otherwise append-to <property name= "MaxSize" >0m</propertY> <!--\D+[KMG]? Suffixes is in terms of 2**10--and <property name= "Maxlines" >0K</property> <!--\D+[KMG]? Suffixes is in terms of thousands-<property name= "daily" >true</property> <!--automatically rota TES When a log message was written after midnight-</filter> <filter enabled= "true" > &LT;TAG&GT;XMLL og</tag> <type>xml</type> <level>TRACE</level> <property name= "filename" >trac e.xml</property> <property name= "Rotate" >true</property> <!--true enables log rotation, Otherwis E Append--<property name= "MaxSize" >100M</property> <!--\D+[KMG]? Suffixes is in terms of 2**10--and <property name= "MaxRecords" >6K</property> <!--\D+[KMG]? Suffixes is in terms of thousands-<property name= "daily" >false</property> <!--automatically rot Ates when a log message was written after midnight--&Gt    </filter> <filter enabled= "false" ><!--Enabled=false means this logger won ' t actually be created- <tag>donotopen</tag> <type>socket</type> <level>FINEST</level> <property Name= "Endpoint" >192.168.0.73:12124</property> <!--recommend UDP Broadcast---<property name= " Protocol ">udp</property> <!--TCP or UDP----</filter></logging>

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.