简单好用的日志框架log4go

log4go的版本,很好用

package main

import (
    "fmt"
    l4g "github.com/ccpaging/log4go"
)

func main() {
    fmt.Println("------------ start --------------")
    // Load the configuration (isn't this easy?)
    l4g.LoadConfiguration("config.xml")

    // And now we're ready!
    l4g.Finest("This will only go to those of you really cool UDP kids!\n  If you change enabled=true.")
    l4g.Debug("Oh no!  %d + %d = %d!", 2, 2, 2+2)
    l4g.Info("About that time, eh chaps?")
    l4g.Warn("About that time, eh chaps?")
    l4g.Error("About that time, \teh chaps?")

    l4g.Close()
    fmt.Println("------------ end --------------")
}

配置文件config.xml

<logging>
  <filter enabled="true">
    <tag>stdout</tag>
    <type>console</type>
    <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) -->
    <level>DEBUG</level>
    <property name="color">true</property>
    <property name="format">[%D %T] [%L] (%S) %M</property>
  </filter>
  <filter enabled="true">
    <tag>file</tag>
    <type>file</type>
    <level>FINEST</level>
    <property name="filename">test.log</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 enables log rotation, otherwise append -->
    <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 -->
    <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands -->
    <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight -->
  </filter>
  <filter enabled="true">
    <tag>xmllog</tag>
    <type>xml</type>
    <level>TRACE</level>
    <property name="filename">trace.xml</property>
    <property name="rotate">true</property> <!-- true enables log rotation, otherwise append -->
    <property name="maxsize">100M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 -->
    <property name="maxrecords">6K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands -->
    <property name="daily">false</property> <!-- Automatically rotates when a log message is written after midnight -->
  </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.1.255:12124</property> <!-- recommend UDP broadcast -->
    <property name="protocol">udp</property> <!-- tcp or udp -->
  </filter>
</logging>
图片.png

图片.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 怎么挑选一款好用的洗发水?美卡建议:根据自身需求来选择 琳琅满目的洗发水让小仙女们看了选择困难症又犯了什么修复、护...
    美小妆阅读 86评论 1 0
  • ubuntu安装Tensorflow的血泪教训 1.在网上找教程的时候一定要注意,别人安装的什么版本和配置 2.要...
    恐龙家族中的老三阅读 320评论 1 0
  • 全世界最好的编辑器VIM之Windows配置(gvim),vundle插件管理,NERDTree插件,ctrlp插...
    dorter阅读 272评论 1 0
  • 说实在话,在这里工作一个月了,还没有一次见到他们本院的医生悉数到场的。我不太确定是不是因为这是宰牲节正式结束后的第...
    东斜_9187阅读 240评论 2 3
  • Vlookup函数功能是“查找引用” Match函数的功能是“查找” Index函数功能是“”引用” 所以,Vlo...
    陶泽昱阅读 1,937评论 0 0