-
Notifications
You must be signed in to change notification settings - Fork 0
/
tail.groovy
47 lines (35 loc) · 865 Bytes
/
tail.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def reader = new Tailer()
def dateTxt = new Date().format("yyyy-MM-dd")
Properties properties = new Properties()
File propertiesFile = new File('config.properties')
propertiesFile.withInputStream {
properties.load(it)
}
def filePath = properties."file-path"
println filePath
reader.tail(new File(filePath)) { println it }
class Tailer {
void tail (File file, Closure c) {
def runnable = {
def reader
try {
reader = file.newReader()
reader.skip(file.length())
def line
def stop = false
while (!stop) {
line = reader.readLine()
if (line) {
c.call(line)
} else {
Thread.currentThread().sleep(1000)
}
}
} finally {
reader?.close()
}
} as Runnable
def t = new Thread(runnable)
t.start()
}
}