Golang's Zap Quest

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

GO Web Programming: http://www.kancloud.cn/kancloud/web-application-with-golang/44105

My Golang project: Https://github.com/javahongxi/go.web.red.git

Uber Zap Test

Package Mainimport ("Go.uber.org/zap" "Time" "Go.uber.org/zap/zapcore" "Net/http" "Bufio" "Os") func mai N () {//logger, _: = Zap. Newproduction ()//defer logger. Sync ()//flushes buffer, if any//sugar: = logger. Sugar ()//url: = "www.baidu.com"//sugar.    Infow ("Failed to fetch URL.",////structured context as loosely-typed key-value pairs. "url", URL,//"attempt", 3,//"Backoff", time. Second,//)//sugar. Infof ("Failed to fetch URL:%s", url) encoder_cfg: = Zapcore.        encoderconfig{//Keys can be anything except the empty string. TimeKey: "T", Levelkey: "L", Namekey: "N", Callerkey: "C", Messagekey : "M", Stacktracekey: "S", Lineending:zapcore. Defaultlineending, Encodelevel:zapcore. Capitallevelencoder, Encodetime:timeencoder, Encodeduration:zapcore. Stringdurationencoder, Encodecaller:zapcore. Shortcallerencoder,} curr_level: = Zap. Newatomiclevelat (Zap. DebugLevel) go func () {http. Listenandserve (": 9090", &curr_level)} () Custom_cfg: = Zap. config{Level:curr_level, Development:true, Encoding: "Console", ENC Oderconfig:encoder_cfg, outputpaths: []string{"stderr", "Qihu-secret-business.log"}, Erroroutputpat HS: []string{"stderr"},} URL: = "www.baidu.com" logger, _: = Custom_cfg. Build () New_logger: = logger. Named ("qihu-secret-business") defer New_logger. Sync () New_logger. Debug ("Adv_event_type_handle", Zap. String ("A", "1")) New_logger.        Info ("Adv_event_type_handle",//structured context as strongly-typed Field values. Zap. String ("url", url), Zap. Int ("Attempt", 3), Zap. Duration ("Backoff", time. Second) Reader: = Bufio. Newreader (OS. Stdin) for {data, _, _: = Reader. ReadLine () Command: = string (data) If command = = "Start" {break}} new_logger. Debug ("Adv_event_type_handle", Zap. String ("B", "2")) New_logger. Info ("Adv_event_type_handle", Zap. String ("C", "3"))}func Timeencoder (t time. Time, enc zapcore. Primitivearrayencoder) {Enc. AppendString ("[" + T.format ("2006-01-02 15:04:05") + "]")}

[2017-05-23 12:08:26] Debugadv_os_businesszap_t/zap_t.go:63adv_event_type_handle{"A": "1"}

[2017-05-23 12:08:26] infoadv_os_businesszap_t/zap_t.go:69adv_event_type_handle{"url": "Www.baidu.com", "attempt": 3, "backoff": "1s"}

Other: Process Start management supervisor, log split logrotate, performance monitoring Https://github.com/grafana/grafana

/etc/supervisor.conf

[Program:simpletest]

command=/home/shenhongxi/go/bin/a

Autostart=true

Autorestart=true

startsecs=10

; logfile=/home/shenhongxi/log/simpletest.log

/etc/logrotate.d/simpletest

/home/shenhongxi/go/*.log {

Missingok

Notifempty

Nocompress

Daily

Rotate 5

Size 204800

}

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.