我命由我,不由天!


  • 搜索
prometheus docker golang linux kubernetes

go-tail包的使用

发表于 2020-11-17 | 分类于 golang | 0 | 阅读次数 487

github地址:https://github.com/hpcloud/tail

package main

import (
	"fmt"
	"github.com/hpcloud/tail"
)

func main(){
	config := tail.Config{
		Location:    &tail.SeekInfo{Offset: 0, Whence: 2}, // Seek to this location before tailing
		ReOpen:  true,    // Reopen recreated files (tail -F)
		MustExist: false,      // Fail early if the file does not exist
		Poll:true,      // Poll for file changes instead of using inotify
		Follow: true, // Continue looking for new lines (tail -f)


	}
	t, err := tail.TailFile("./tail.log", config)
	if err != nil {
		fmt.Println("open file:",err)
	}
	for line := range t.Lines {
		fmt.Println(line.Text)
	}
}
  • 本文作者: Dante
  • 本文链接: https://gaodongfei.com/archives/go-tail
  • 版权声明: 本博客所有文章除特别声明外,均采用CC BY-NC-SA 3.0 许可协议。转载请注明出处!
# golang
leetcode-234-回文链表
go-Viper 配置文件包
  • 文章目录
  • 站点概览
Dante

Dante

119 日志
5 分类
5 标签
RSS
Creative Commons
0%
© 2023 Dante
由 Halo 强力驱动
|
主题 - NexT.Pisces v5.1.4
沪ICP备2020033702号