zoukankan      html  css  js  c++  java
  • Go tail库

    HP团队出的tail库,常用于日志收集

    示例代码:

    package main
    
    import (
        "github.com/hpcloud/tail"
        "fmt"
        "time"
    )
    
    func main() {
        filename := "./my.log"
        tailFile, 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
        }
    
        for true {
            msg, ok := <- tailFile.Lines
            if !ok {
                fmt.Printf("tail file close reopen, filename: %s
    ", tailFile.Filename)
                time.Sleep(100 * time.Millisecond)
                continue
            }
            fmt.Println("msg:", msg)
        }
    }
  • 相关阅读:
    poj1837 Balance

    字符流
    字节流
    File类
    this和static
    异常
    接口
    抽象类
    多态
  • 原文地址:https://www.cnblogs.com/vincenshen/p/9783267.html
Copyright © 2011-2022 走看看