{"id":24290,"date":"2021-11-28T16:36:11","date_gmt":"2021-11-28T08:36:11","guid":{"rendered":"https:\/\/aqzt.com\/24290.html"},"modified":"2021-11-28T16:36:11","modified_gmt":"2021-11-28T08:36:11","slug":"go%e9%a1%b9%e7%9b%ae%e5%ae%9e%e6%88%98%ef%bc%9a%e6%89%93%e9%80%a0%e9%ab%98%e5%b9%b6%e5%8f%91%e6%97%a5%e5%bf%97%e9%87%87%e9%9b%86%e7%b3%bb%e7%bb%9f%ef%bc%88%e5%9b%9b","status":"publish","type":"post","link":"https:\/\/aqzt.com\/24290.html","title":{"rendered":"Go\u9879\u76ee\u5b9e\u6218\uff1a\u6253\u9020\u9ad8\u5e76\u53d1\u65e5\u5fd7\u91c7\u96c6\u7cfb\u7edf\uff08\u56db)"},"content":{"rendered":"<h2>\u524d\u60c5\u56de\u987e<\/h2>\n<p>\u524d\u6587\u6211\u4eec\u5b8c\u6210\u4e86\u5982\u4e0b\u76ee\u6807<br \/>\n<!-- -->1 \u9879\u76ee\u67b6\u6784\u6574\u4f53\u7f16\u5199<br \/>\n<!-- -->2 \u4f7f\u6846\u67b6\u652f\u6301\u70ed\u66f4\u65b0<\/p>\n<\/p>\n<h2>\u672c\u8282\u76ee\u6807<\/h2>\n<p>\u5728\u524d\u6587\u7684\u6846\u67b6\u57fa\u7840\u4e0a\uff0c\u6211\u4eec<br \/>\n<!-- -->1 \u5c06\u4e4b\u524d\u5b9e\u73b0\u7684\u65e5\u5fd7\u76d1\u63a7\u529f\u80fd\u6574\u5408\u5230\u6846\u67b6\u4e2d\u3002<br \/>\n<!-- -->2 \u4e00\u4e2a\u65e5\u5fd7\u5bf9\u5e94\u4e00\u4e2a\u76d1\u63a7\u534f\u7a0b\uff0c\u5f53\u914d\u7f6e\u70ed\u66f4\u65b0\u540e\u6839\u636e\u65b0\u914d\u7f6e\u52a8\u6001\u5173\u95ed\u548c\u542f\u52a8\u534f\u7a0b\u3002<br \/>\n<!-- -->3 \u7f16\u5199\u6d4b\u8bd5\u4ee3\u7801\uff0c\u6a21\u62df\u5411\u6587\u4ef6\u4e2d\u4e0d\u65ad\u5199\u5165\u65e5\u5fd7\uff0c\u5e76\u5907\u4efd\u65e5\u5fd7\uff0c\u89c2\u5bdf\u76d1\u63a7\u529f\u80fd\u662f\u5426\u5065\u58ee\u3002<\/p>\n<h2>\u589e\u52a0\u534f\u7a0b\u76d1\u63a7\u65e5\u5fd7\u6587\u4ef6<\/h2>\n<p>\u6211\u4eec\u5c06\u4e4b\u524d\u5b9e\u73b0\u7684\u65e5\u5fd7\u76d1\u63a7\u529f\u80fd\u6574\u5408\u5230\u73b0\u6709\u6846\u67b6\uff0c\u6587\u4ef6\u7ed3\u6784\u5982\u4e0b<br \/>\n<!-- -->logdir\u4e3a\u5b58\u50a8\u65e5\u5fd7\u7684\u6587\u4ef6\u5939\uff0c\u6a21\u62df\u4e0d\u540c\u7cfb\u7edf\u8bb0\u5f55\u7684\u65e5\u5fd7\u3002\u5b9e\u9645\u751f\u4ea7\u4e2d\u4e0d\u540c\u7cfb\u7edf\u4f1a\u81ea\u5df1\u8bb0\u5f55\u65e5\u5fd7\u5e76\u4fdd\u5b58\u5728\u6307\u5b9a\u6587\u4ef6\u5939\u4e2d\uff0clogdir\u6a21\u62df\u7684\u5c31\u662f\u8fd9\u4e9b\u6307\u5b9a\u6587\u4ef6\u3002<br \/>\n<!-- -->logtailf\u5b9e\u73b0\u65e5\u5fd7\u6587\u4ef6\u7684\u76d1\u63a7\u529f\u80fd\u3002<br \/>\n<!-- -->writefile\u6a21\u62df\u4e0d\u540c\u7cfb\u7edf\u5411\u6307\u5b9a\u6587\u4ef6\u5939\u5199\u5165\u65e5\u5fd7\uff0c\u7528\u6765\u6d4b\u8bd5\u65e5\u5fd7\u5199\u5165\u548c\u5907\u4efd\u65f6\uff0c\u6211\u4eec\u7684\u91c7\u96c6\u7cfb\u7edf\u662f\u5426\u5065\u58ee\u3002<br \/>\n<!-- -->\u6211\u4eec\u5148\u770b\u4e0blogtailf.go<\/p>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-go\" style=\"overflow:auto;white-space:nowrap;width:800px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/>39<br \/><\/div><\/td><td><div class=\"text codecolorer\">1func WatchLogFile(datapath string, ctx context.Context) {<br \/>\n2 &nbsp; fmt.Println(&amp;quot;begin goroutine watch log file &amp;quot;, datapath)<br \/>\n3 &nbsp; tailFile, err := tail.TailFile(datapath, tail.Config{<br \/>\n4 &nbsp; &nbsp; &nbsp; \/\/\u6587\u4ef6\u88ab\u79fb\u9664\u6216\u88ab\u6253\u5305\uff0c\u9700\u8981\u91cd\u65b0\u6253\u5f00<br \/>\n5 &nbsp; &nbsp; &nbsp; ReOpen: true,<br \/>\n6 &nbsp; &nbsp; &nbsp; \/\/\u5b9e\u65f6\u8ddf\u8e2a<br \/>\n7 &nbsp; &nbsp; &nbsp; Follow: true,<br \/>\n8 &nbsp; &nbsp; &nbsp; \/\/\u5982\u679c\u7a0b\u5e8f\u51fa\u73b0\u5f02\u5e38\uff0c\u4fdd\u5b58\u4e0a\u6b21\u8bfb\u53d6\u7684\u4f4d\u7f6e\uff0c\u907f\u514d\u91cd\u65b0\u8bfb\u53d6<br \/>\n9 &nbsp; &nbsp; &nbsp; Location: &amp;amp;tail.SeekInfo{Offset: 0, Whence: 2},<br \/>\n10&nbsp; &nbsp; &nbsp; \/\/\u652f\u6301\u6587\u4ef6\u4e0d\u5b58\u5728<br \/>\n11&nbsp; &nbsp; &nbsp; MustExist: false,<br \/>\n12&nbsp; &nbsp; &nbsp; Poll: &nbsp; &nbsp; &nbsp;true,<br \/>\n13&nbsp; })<br \/>\n14<br \/>\n15&nbsp; if err != nil {<br \/>\n16&nbsp; &nbsp; &nbsp; fmt.Println(&amp;quot;tail file err:&amp;quot;, err)<br \/>\n17&nbsp; &nbsp; &nbsp; return<br \/>\n18&nbsp; }<br \/>\n19<br \/>\n20&nbsp; for true {<br \/>\n21&nbsp; &nbsp; &nbsp; select {<br \/>\n22&nbsp; &nbsp; &nbsp; case msg, ok := &amp;lt;-tailFile.Lines:<br \/>\n23&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if !ok {<br \/>\n24&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fmt.Printf(&amp;quot;tail file close reopen, filename: %s\\n&amp;quot;, tailFile.Filename)<br \/>\n25&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; time.Sleep(100 * time.Millisecond)<br \/>\n26&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue<br \/>\n27&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>\n28&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/fmt.Println(&amp;quot;msg:&amp;quot;, msg)<br \/>\n29&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/\u53ea\u6253\u5370text<br \/>\n30&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(&amp;quot;msg:&amp;quot;, msg.Text)<br \/>\n31&nbsp; &nbsp; &nbsp; case &amp;lt;-ctx.Done():<br \/>\n32&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(&amp;quot;receive main gouroutine exit msg&amp;quot;)<br \/>\n33&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(&amp;quot;watch log file &amp;quot;, datapath, &amp;quot; goroutine exited&amp;quot;)<br \/>\n34&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return<br \/>\n35&nbsp; &nbsp; &nbsp; }<br \/>\n36<br \/>\n37&nbsp; }<br \/>\n38}<br \/>\n39<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>\u53ea\u6709\u4e00\u4e2a\u51fd\u6570WatchLogFile\u7528\u6765\u76d1\u63a7\u6307\u5b9a\u8def\u5f84\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u4e24\u4e2a\u53c2\u6570\u5206\u522b\u4e3a\u65e5\u5fd7\u8def\u5f84\u548c\u4e0a\u4e0b\u6587\u5f00\u5173\uff0c\u5f00\u5173\u7528\u6765\u5173\u95ed\u8fd9\u4e2a\u534f\u7a0b\uff0c\u6574\u4f53\u529f\u80fd\u548c\u524d\u51e0\u7bc7\u8bb2\u8ff0\u7684\u4e00\u6837\uff0c\u4e0d\u505a\u8d58\u8ff0\u3002<br \/>\n<!-- -->\u63a5\u4e0b\u6765\u6211\u4eec\u5728main.go\u4e2d\u586b\u52a0\u534f\u7a0b\u542f\u52a8\u903b\u8f91\u76d1\u63a7\u65e5\u5fd7\u6587\u4ef6<\/p>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-go\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/><\/div><\/td><td><div class=\"text codecolorer\">1func ConstructMgr(configPaths interface{}) {<br \/>\n2 &nbsp; configDatas := configPaths.(map[string]interface{})<br \/>\n3 &nbsp; for conkey, confval := range configDatas {<br \/>\n4 &nbsp; &nbsp; &nbsp; configData := new(logconfig.ConfigData)<br \/>\n5 &nbsp; &nbsp; &nbsp; configData.ConfigKey = conkey<br \/>\n6 &nbsp; &nbsp; &nbsp; configData.ConfigValue = confval.(string)<br \/>\n7 &nbsp; &nbsp; &nbsp; ctx, cancel := context.WithCancel(context.Background())<br \/>\n8 &nbsp; &nbsp; &nbsp; configData.ConfigCancel = cancel<br \/>\n9 &nbsp; &nbsp; &nbsp; configMgr[conkey] = configData<br \/>\n10&nbsp; &nbsp; &nbsp; go logtailf.WatchLogFile(configData.ConfigValue,<br \/>\n11&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx)<br \/>\n12&nbsp; }<br \/>\n13}<br \/>\n14<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>ConstructMgr\u65b0\u589e\u4e86\u534f\u7a0b\u542f\u52a8\u903b\u8f91\uff0c\u5e76\u4e14\u5c06\u534f\u7a0b\u7684ctx\u4fdd\u5b58\u5728map\u4e2d\uff0c\u8fd9\u6837\u4e3b\u534f\u7a0b\u53ef\u4ee5\u6839\u636e\u70ed\u66f4\u65b0\u542f\u52a8\u548c\u5173\u95ed\u8fd9\u4e2a\u534f\u7a0b\u3002\u7136\u540e\u6211\u5b8c\u5584\u4e86main\u51fd\u6570\u4e2d\u7684\u6790\u6784\u51fd\u6570<\/p>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-go\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/><\/div><\/td><td><div class=\"text codecolorer\">1defer func() {<br \/>\n2 &nbsp; &nbsp; &nbsp; mainOnce.Do(func() {<br \/>\n3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if err := recover(); err != nil {<br \/>\n4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(&amp;quot;main goroutine panic &amp;quot;, err) \/\/ \u8fd9\u91cc\u7684err\u5176\u5b9e\u5c31\u662fpanic\u4f20\u5165\u7684\u5185\u5bb9<br \/>\n5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>\n6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cancel()<br \/>\n7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for _, oldval := range configMgr {<br \/>\n8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oldval.ConfigCancel()<br \/>\n9 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>\n10&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; configMgr = nil<br \/>\n11&nbsp; &nbsp; &nbsp; })<br \/>\n12&nbsp; }()<br \/>\n13<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>\u6790\u6784\u51fd\u6570\u91cc\u904d\u5386map\uff0c\u5173\u95ed\u6240\u6709\u76d1\u63a7\u534f\u7a0b\uff0c\u5e76\u4e14\u5c06map\u8bbe\u7f6e\u4e3anil\u56de\u6536\u8d44\u6e90\u3002\u5728main\u51fd\u6570\u4e2d\u6dfb\u52a0\u70ed\u66f4\u65b0\u63a7\u5236\u534f\u7a0b\u5f00\u5173\u3002<\/p>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-go\" style=\"overflow:auto;white-space:nowrap;width:800px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/><\/div><\/td><td><div class=\"text codecolorer\">1for oldkey, oldval := range configMgr {<br \/>\n2 &nbsp; _, ok := pathDataNew[oldkey]<br \/>\n3 &nbsp; if ok {<br \/>\n4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue<br \/>\n5 &nbsp; &nbsp; &nbsp; }<br \/>\n6 &nbsp; oldval.ConfigCancel()<br \/>\n7 &nbsp; delete(configMgr, oldkey)<br \/>\n8}<br \/>\n9<br \/>\n10for conkey, conval := range pathDataNew {<br \/>\n11&nbsp; oldval, ok := configMgr[conkey]<br \/>\n12&nbsp; if !ok {<br \/>\n13&nbsp; &nbsp; &nbsp; configData := new(logconfig.ConfigData)<br \/>\n14&nbsp; &nbsp; &nbsp; configData.ConfigKey = conkey<br \/>\n15&nbsp; &nbsp; &nbsp; configData.ConfigValue = conval.(string)<br \/>\n16&nbsp; &nbsp; &nbsp; ctx, cancel := context.WithCancel(context.Background())<br \/>\n17&nbsp; &nbsp; &nbsp; configData.ConfigCancel = cancel<br \/>\n18&nbsp; &nbsp; &nbsp; configMgr[conkey] = configData<br \/>\n19&nbsp; &nbsp; &nbsp; fmt.Println(conval.(string))<br \/>\n20&nbsp; &nbsp; &nbsp; go logtailf.WatchLogFile(configData.ConfigValue,<br \/>\n21&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx)<br \/>\n22&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; continue<br \/>\n23&nbsp; }<br \/>\n24<br \/>\n25&nbsp; if oldval.ConfigValue != conval.(string) {<br \/>\n26&nbsp; &nbsp; &nbsp; oldval.ConfigValue = conval.(string)<br \/>\n27&nbsp; &nbsp; &nbsp; oldval.ConfigCancel()<br \/>\n28&nbsp; &nbsp; &nbsp; ctx, cancel := context.WithCancel(context.Background())<br \/>\n29&nbsp; &nbsp; &nbsp; oldval.ConfigCancel = cancel<br \/>\n30&nbsp; &nbsp; &nbsp; go logtailf.WatchLogFile(conval.(string),<br \/>\n31&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ctx)<br \/>\n32&nbsp; &nbsp; &nbsp; continue<br \/>\n33&nbsp; }<br \/>\n34}<br \/>\n35<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>\u5bf9\u6bd4\u65b0\u65e7\u914d\u7f6e\uff0c\u5982\u679c\u8def\u5f84\u53d6\u6d88\uff0c\u5219\u505c\u6b62\u76d1\u63a7\u5176\u7684\u534f\u7a0b\uff0c\u5982\u679c\u8def\u5f84\u65b0\u589e\u6216\u4fee\u6539\uff0c\u5219\u542f\u52a8\u65b0\u7684\u534f\u7a0b\u3002<br \/>\n<!-- -->\u8fd9\u6837\u6211\u4eec\u542f\u52a8\u7a0b\u5e8f\u770b\u5230\u5982\u4e0b\u6548\u679c<\/p>\n<h2>\u7f16\u5199\u6d4b\u8bd5\u6587\u4ef6\uff0c\u6a21\u62df\u65e5\u5fd7\u5199\u5165\u548c\u5907\u4efd<\/h2>\n<p>\u6211\u4eec\u5728writefile.go\u4e2d\u5b9e\u73b0\u65e5\u5fd7\u5199\u5165\u548c\u5907\u4efd\uff0c\u8fd9\u90e8\u5206\u5185\u5bb9\u524d\u51e0\u7bc7\u6709\u8bb2\u89e3\uff0c\u6211\u53ea\u662f\u5c06\u539f\u6765\u5b9e\u73b0\u7684\u529f\u80fd\u642c\u8fc7\u6765<\/p>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-go\" style=\"overflow:auto;white-space:nowrap;width:800px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/>38<br \/>39<br \/>40<br \/>41<br \/>42<br \/><\/div><\/td><td><div class=\"text codecolorer\">1func writeLog(datapath string, wg *sync.WaitGroup) {<br \/>\n2 &nbsp; filew, err := os.OpenFile(datapath, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0644)<br \/>\n3 &nbsp; if err != nil {<br \/>\n4 &nbsp; &nbsp; &nbsp; fmt.Println(&amp;quot;open file error &amp;quot;, err.Error())<br \/>\n5 &nbsp; &nbsp; &nbsp; return<br \/>\n6 &nbsp; }<br \/>\n7 &nbsp; defer func() {<br \/>\n8 &nbsp; &nbsp; &nbsp; wg.Done()<br \/>\n9 &nbsp; }()<br \/>\n10&nbsp; w := bufio.NewWriter(filew)<br \/>\n11&nbsp; for i := 0; i &amp;lt; 20; i++ {<br \/>\n12&nbsp; &nbsp; &nbsp; timeStr := time.Now().Format(&amp;quot;2006-01-02 15:04:05&amp;quot;)<br \/>\n13&nbsp; &nbsp; &nbsp; fmt.Fprintln(w, &amp;quot;Hello current time is &amp;quot;+timeStr)<br \/>\n14&nbsp; &nbsp; &nbsp; time.Sleep(time.Millisecond * 100)<br \/>\n15&nbsp; &nbsp; &nbsp; w.Flush()<br \/>\n16&nbsp; }<br \/>\n17&nbsp; logBak := time.Now().Format(&amp;quot;20060102150405&amp;quot;) + &amp;quot;.txt&amp;quot;<br \/>\n18&nbsp; logBak = path.Join(path.Dir(datapath), logBak)<br \/>\n19&nbsp; filew.Close()<br \/>\n20&nbsp; err = os.Rename(datapath, logBak)<br \/>\n21&nbsp; if err != nil {<br \/>\n22&nbsp; &nbsp; &nbsp; fmt.Println(&amp;quot;Rename error &amp;quot;, err.Error())<br \/>\n23&nbsp; &nbsp; &nbsp; return<br \/>\n24&nbsp; }<br \/>\n25}<br \/>\n26<br \/>\n27func main() {<br \/>\n28&nbsp; v := viper.New()<br \/>\n29&nbsp; configPaths, confres := logconfig.ReadConfig(v)<br \/>\n30&nbsp; if !confres {<br \/>\n31&nbsp; &nbsp; &nbsp; fmt.Println(&amp;quot;config read failed&amp;quot;)<br \/>\n32&nbsp; &nbsp; &nbsp; return<br \/>\n33&nbsp; }<br \/>\n34&nbsp; wg := &amp;amp;sync.WaitGroup{}<br \/>\n35<br \/>\n36&nbsp; for _, confval := range configPaths.(map[string]interface{}) {<br \/>\n37&nbsp; &nbsp; &nbsp; wg.Add(1)<br \/>\n38&nbsp; &nbsp; &nbsp; go writeLog(confval.(string), wg)<br \/>\n39&nbsp; }<br \/>\n40&nbsp; wg.Wait()<br \/>\n41}<br \/>\n42<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>\u6839\u636e\u914d\u7f6e\u6587\u4ef6\u542f\u52a8\u591a\u4e2a\u534f\u7a0b\uff0c\u5411\u65e5\u5fd7\u6587\u4ef6\u4e2d\u4e0d\u65ad\u5199\u5165\u65e5\u5fd7\uff0c\u5199\u516520\u6761\u540e\u5907\u4efd\u65e5\u5fd7\uff0c\u6211\u4eec\u542f\u52a8\u65e5\u5fd7\u6536\u96c6\u7a0b\u5e8f\u548c\u8fd9\u4e2a\u6d4b\u8bd5\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u770b\u5230\u65e5\u5fd7\u4e0d\u65ad\u88ab\u5199\u5165\uff0c\u65e5\u5fd7\u6536\u96c6\u7a0b\u5e8f\u4e0d\u65ad\u6253\u5370\u65e5\u5fd7\u65b0\u589e\u7684\u5185\u5bb9<br \/>\n<!-- -->\u65e5\u5fd7\u5907\u4efd\u4e3a\u4e0d\u540c\u7684\u6587\u4ef6<br \/>\n<!-- -->\u53ef\u4ee5\u770b\u5230\u65e5\u5fd7\u6536\u96c6\u7cfb\u7edf\u5728\u65e5\u5fd7\u4e0d\u65ad\u5199\u5165\u65f6\uff0c\u53ef\u4ee5\u5065\u58ee\u8fd0\u884c<\/p>\n<h2>\u70ed\u66f4\u65b0\u63a7\u5236\u76d1\u63a7\u534f\u7a0b\u6253\u5f00\u548c\u5173\u95ed<\/h2>\n<p>\u73b0\u5728config.yaml\u6587\u4ef6\u4e2d\u8def\u5f84\u8bb0\u5f55\u5982\u4e0b<\/p>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-go\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/><\/div><\/td><td><div class=\"text codecolorer\">1configpath: <br \/>\n2 &nbsp;logdir1: &amp;quot;D:\/golangwork\/src\/golang-\/logcatchsys\/logdir1\/log.txt&amp;quot;<br \/>\n3 &nbsp;logdir2: &amp;quot;D:\/golangwork\/src\/golang-\/logcatchsys\/logdir2\/log.txt&amp;quot;<br \/>\n4 &nbsp;logdir3: &amp;quot;D:\/golangwork\/src\/golang-\/logcatchsys\/logdir3\/log.txt&amp;quot;<br \/>\n5<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>\u6211\u4eec\u542f\u52a8\u65e5\u5fd7\u6536\u96c6\u7a0b\u5e8f\uff0c\u6a21\u62df\u70ed\u66f4\u65b0\u914d\u7f6e\uff0c\u5c06logdir3\u8fd9\u6761\u6570\u636e\u4fee\u6539, \u914d\u7f6e\u53d8\u4e3a\u5982\u4e0b<\/p>\n<pre>\n\n<div class=\"codecolorer-container text solarized-dark language-go\" style=\"overflow:auto;white-space:nowrap;width:800px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/><\/div><\/td><td><div class=\"text codecolorer\">1configpath: <br \/>\n2 &nbsp;logdir1: &amp;quot;D:\/golangwork\/src\/golang-\/logcatchsys\/logdir1\/log.txt&amp;quot;<br \/>\n3 &nbsp;logdir2: &amp;quot;D:\/golangwork\/src\/golang-\/logcatchsys\/logdir2\/log.txt&amp;quot;<br \/>\n4 &nbsp;logdir4: &amp;quot;D:\/golangwork\/src\/golang-\/logcatchsys\/logdir4\/log.txt&amp;quot;<br \/>\n5<\/div><\/td><\/tr><\/tbody><\/table><\/div>\n\n<\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u7a0b\u5e8f\u4f5c\u51fa\u68c0\u6d4b\uff0c\u5e76\u5173\u95ed\u4e86\u66fe\u7ecf\u76d1\u63a7logdir3\u7684\u534f\u7a0b\uff0c\u5e76\u542f\u52a8\u4e86\u65b0\u7684\u534f\u7a0b\u76d1\u63a7logdir4\uff0c\u800c\u5176\u4ed6\u7684\u65e5\u5fd7\u76d1\u63a7\u534f\u7a0b\u4e0d\u53d7\u5f71\u54cd\uff0c\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<p>\u6e90\u7801\u4e0b\u8f7d\u5730\u5740<br \/>\n<a href=\"https:\/\/github.com\/secondtonone1\/golang-\/tree\/master\/logcatchsys\">https:\/\/github.com\/secondtonone1\/golang-\/tree\/master\/logcatchsys<\/a><br \/>\n<!-- -->\u6211\u7684\u516c\u4f17\u53f7<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u60c5\u56de\u987e \u524d\u6587\u6211\u4eec\u5b8c\u6210\u4e86\u5982\u4e0b\u76ee\u6807 1 \u9879\u76ee\u67b6\u6784\u6574\u4f53\u7f16\u5199 2 \u4f7f\u6846\u67b6\u652f\u6301\u70ed\u66f4\u65b0 \u672c\u8282\u76ee\u6807 \u5728\u524d\u6587\u7684\u6846\u67b6\u57fa\u7840\u4e0a\uff0c\u6211\u4eec 1 \u5c06\u4e4b\u524d\u5b9e\u73b0\u7684\u65e5\u5fd7\u76d1\u63a7\u529f\u80fd\u6574\u5408\u5230\u6846\u67b6\u4e2d\u3002 2 \u4e00\u4e2a\u65e5\u5fd7\u5bf9\u5e94\u4e00\u4e2a\u76d1\u63a7\u534f\u7a0b\uff0c\u5f53\u914d\u7f6e\u70ed\u66f4\u65b0\u540e\u6839\u636e\u65b0\u914d\u7f6e\u52a8\u6001\u5173\u95ed\u548c\u542f\u52a8\u534f\u7a0b\u3002 3 \u7f16\u5199\u6d4b\u8bd5\u4ee3\u7801\uff0c\u6a21\u62df\u5411\u6587\u4ef6\u4e2d\u4e0d\u65ad\u5199\u5165\u65e5\u5fd7\uff0c\u5e76\u5907\u4efd\u65e5\u5fd7\uff0c\u89c2\u5bdf\u76d1\u63a7\u529f\u80fd\u662f\u5426\u5065\u58ee\u3002 \u589e\u52a0\u534f\u7a0b\u76d1\u63a7\u65e5\u5fd7\u6587\u4ef6 \u6211\u4eec\u5c06\u4e4b\u524d\u5b9e\u73b0\u7684\u65e5\u5fd7\u76d1\u63a7\u529f\u80fd\u6574\u5408\u5230\u73b0\u6709\u6846\u67b6\uff0c\u6587\u4ef6\u7ed3\u6784\u5982\u4e0b logdir\u4e3a\u5b58\u50a8\u65e5\u5fd7\u7684\u6587\u4ef6\u5939\uff0c\u6a21\u62df\u4e0d\u540c\u7cfb\u7edf\u8bb0\u5f55\u7684\u65e5\u5fd7\u3002\u5b9e\u9645\u751f\u4ea7\u4e2d\u4e0d\u540c\u7cfb\u7edf\u4f1a\u81ea\u5df1\u8bb0\u5f55\u65e5\u5fd7\u5e76\u4fdd\u5b58\u5728\u6307\u5b9a\u6587\u4ef6\u5939\u4e2d\uff0clogdir\u6a21\u62df<\/p>\n","protected":false},"author":1,"featured_media":6522,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[2],"tags":[292,21,22,500],"collection":[],"_links":{"self":[{"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/posts\/24290"}],"collection":[{"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/comments?post=24290"}],"version-history":[{"count":0,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/posts\/24290\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/media\/6522"}],"wp:attachment":[{"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/media?parent=24290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/categories?post=24290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/tags?post=24290"},{"taxonomy":"collection","embeddable":true,"href":"https:\/\/aqzt.com\/wp-json\/wp\/v2\/collection?post=24290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}