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)
| 101 | // invoke the `Wait` or `Err` method after finishing reading from the |
| 102 | // `Lines` channel. |
| 103 | func 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. |
searching dependent graphs…