zoukankan      html  css  js  c++  java
  • go tail

    安装导入

    go get github.com/hpcloud/tail
    import "github.com/hpcloud/tail"
    

    使用

    package main
    
    import (
    	"fmt"
    	"github.com/hpcloud/tail"
    	"time"
    )
    func main() {
    	filename := "E:\project\kafka_2.12-0.11.0.0\config\server.properties"
    	//filename := ".\my.log"
    	tails, err := tail.TailFile(filename, tail.Config{
    		ReOpen:    true,
    		Follow:    true,
    		//Location:  &tail.SeekInfo{Offset: 0, Whence: 2},
    		MustExist: false,	
    			Poll:      true,
    	})
    	if err != nil {
    		fmt.Println("tail file err:", err)
    		return
    	}
    	var msg *tail.Line
    	var ok bool
    	for true {
    		msg, ok = <-tails.Lines
    		if !ok {
    			fmt.Printf("tail file close reopen, filename:%s
    ", tails.Filename)
    			time.Sleep(100 * time.Millisecond)
    			continue
    		}
    		fmt.Println("msg:", msg)
    	}
    }
    

      

  • 相关阅读:
    diff
    tar
    ln
    setfacl
    组件建站
    容器组件
    组件需求
    页面结构
    字体
    轮博图加元素动效的动效ransition
  • 原文地址:https://www.cnblogs.com/shhnwangjian/p/7526945.html
Copyright © 2011-2022 走看看