Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LaaS
logstash-forwarder
Commits
74c4578b
Commit
74c4578b
authored
Jul 02, 2013
by
Jordan Sissel
Browse files
- Allow harvesters to start up at a given file offset
parent
17712122
Changes
1
Hide whitespace changes
Inline
Side-by-side
harvester.go
View file @
74c4578b
...
...
@@ -12,6 +12,7 @@ import (
type
Harvester
struct
{
Path
string
/* the file path to harvest */
Fields
map
[
string
]
string
Offset
int64
file
os
.
File
/* the file being watched */
}
...
...
@@ -23,7 +24,11 @@ func (h *Harvester) Harvest(output chan *FileEvent) {
// TODO(sissel): Sleep when there's nothing to do
// TODO(sissel): Quit if we think the file is dead (file dev/inode changed, no data in X seconds)
log
.
Printf
(
"Starting harvester: %s
\n
"
,
h
.
Path
)
if
h
.
Offset
>
0
{
log
.
Printf
(
"Starting harvester at position %d: %s
\n
"
,
h
.
Offset
,
h
.
Path
)
}
else
{
log
.
Printf
(
"Starting harvester: %s
\n
"
,
h
.
Path
)
}
file
:=
h
.
open
()
info
,
_
:=
file
.
Stat
()
// TODO(sissel): Check error
...
...
@@ -67,7 +72,7 @@ func (h *Harvester) Harvest(output chan *FileEvent) {
line
++
event
:=
&
FileEvent
{
Source
:
&
h
.
Path
,
Offset
:
uint64
(
offset
)
,
Offset
:
offset
,
Line
:
line
,
Text
:
text
,
Fields
:
&
h
.
Fields
,
...
...
@@ -100,9 +105,12 @@ func (h *Harvester) open() *os.File {
}
}
// TODO(sissel): In the future, use the registrary to determine where to seek.
// TODO(sissel): Only seek if the file is a file, not a pipe or socket.
file
.
Seek
(
0
,
os
.
SEEK_END
)
if
h
.
Offset
>
0
{
file
.
Seek
(
h
.
Offset
,
os
.
SEEK_SET
)
}
else
{
file
.
Seek
(
0
,
os
.
SEEK_END
)
}
return
file
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment