MCPcopy Index your code
hub / github.com/hpcloud/tail / TailFile

Function TailFile

tail.go:103–136  ·  view source on GitHub ↗

TailFile begins tailing the file. Output stream is made available via the `Tail.Lines` channel. To handle errors during tailing, invoke the `Wait` or `Err` method after finishing reading from the `Lines` channel.

(filename string, config Config)

Source from the content-addressed store, hash-verified

101// invoke the `Wait` or `Err` method after finishing reading from the
102// `Lines` channel.
103func TailFile(filename string, config Config) (*Tail, error) {
104 if config.ReOpen && !config.Follow {
105 util.Fatal("cannot set ReOpen without Follow.")
106 }
107
108 t := &Tail{
109 Filename: filename,
110 Lines: make(chan *Line),
111 Config: config,
112 }
113
114 // when Logger was not specified in config, use default logger
115 if t.Logger == nil {
116 t.Logger = log.New(os.Stderr, "", log.LstdFlags)
117 }
118
119 if t.Poll {
120 t.watcher = watch.NewPollingFileWatcher(filename)
121 } else {
122 t.watcher = watch.NewInotifyFileWatcher(filename)
123 }
124
125 if t.MustExist {
126 var err error
127 t.file, err = OpenFile(t.Filename)
128 if err != nil {
129 return nil, err
130 }
131 }
132
133 go t.tailFileSync()
134
135 return t, nil
136}
137
138// Return the file's current position, like stdio's ftell().
139// But this value is not very accurate.

Callers 4

TestMustExistFunction · 0.85
TestStopFunction · 0.85
StartTailMethod · 0.85

Calls 3

tailFileSyncMethod · 0.95
FatalMethod · 0.80
OpenFileFunction · 0.70

Tested by 4

TestMustExistFunction · 0.68
TestStopFunction · 0.68
StartTailMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…