github.com/nxadm/tail@v1.4.12-0.20231010141446-ba755e4d73b6/examples/01-tailAndPrint/main.go (about)

     1  // Tail a file and print its contents.
     2  //
     3  // In this example you can add lines to the syslog log by using the logger
     4  // command. Exit with Ctrl+C.
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/nxadm/tail"
    11  )
    12  
    13  var logFile = "/var/log/syslog"
    14  
    15  func main() {
    16  	t, err := tail.TailFile(logFile, tail.Config{Follow: true})
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  
    21  	for line := range t.Lines {
    22  		fmt.Println(line.Text)
    23  	}
    24  }