-
Notifications
You must be signed in to change notification settings - Fork 1
/
logwatch.coffee
46 lines (32 loc) · 1.04 KB
/
logwatch.coffee
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
fs = require('fs')
class FileWatcher
constructor: (file) ->
@listen "/mnt/" + file + "/data/graph.db/messages.log"
@listen "/mnt/" + file + "/data/log/console.log"
@listen "/mnt/" + file + "/data/log/neo4j.log"
watching = []
listen: (file) ->
return if watching[file]
try
console.log fs.statSync(file).isFIFO
catch e
console.log e
console.log "start watch " + file
watching[file] = stream = fs.createReadStream(file, {encoding: "UTF8"})
stream.on "data", (d)->
console.log file + " " + d
self = this
stream.on "end", ->
console.log file + " end"
delete watching[file]
self.listen file
stream.on "error", (e)->
console.log file + " error " + e
delete watching[file]
try
stream.close()
catch e
consoloe.log e
#stream.on "close", ->
# console.log file + " close"
f = new FileWatcher("024ed856b")