摘要: 主要用于Web服务日志最新行查看。 package main import( "fmt" "os" "bytes") const ( defaultBufSize = 4096) func tail( filename string, n int ) (lines string,err error) { f,e := ...
主要用于Web服务日志最新行查看。
package main
import( "fmt" "os" "bytes" )
const ( defaultBufSize = 4096 )
func tail( filename string, n int ) (lines []string,err error) { f,e := os.Stat( filename ) if e == nil { size := f.Size() var fi *os.File fi,err = os.Open(filename) if err == nil{ b := make( []byte,defaultBufSize ) sz := int64(defaultBufSize) nn := n bTail := bytes.NewBuffer([]byte{}) istart := size flag := true for flag { if istart