Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WUI/API: fix log file path #330 #332
- Loading branch information
Showing
2 changed files
with
78 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,43 @@ | ||
(function() { | ||
|
||
if (['wui', 'operator', 'scheduler'].indexOf(request.param.name) === -1) { | ||
return response.error(404); | ||
} | ||
|
||
var filename = './log/' + request.param.name; | ||
|
||
if (!fs.existsSync(filename)) { | ||
response.head(204); | ||
response.end(''); | ||
return; | ||
} | ||
|
||
response.head(200); | ||
|
||
response.write(new Array(1024).join(' ')); | ||
|
||
var tailf = child_process.spawn('tail', ['-f', '-n', '100', filename]); | ||
children.push(tailf.pid); | ||
|
||
tailf.stdout.pipe(response); | ||
|
||
tailf.on('exit', function(code) { | ||
response.end(); | ||
}); | ||
|
||
request.on('close', function() { | ||
tailf.kill('SIGKILL'); | ||
}); | ||
|
||
(function() { | ||
|
||
if (['wui', 'operator', 'scheduler'].indexOf(request.param.name) === -1) { | ||
return response.error(404); | ||
} | ||
|
||
let filename = ""; | ||
switch (request.param.name) { | ||
case "wui": | ||
filename = define.WUI_LOG_FILE; | ||
break; | ||
case "scheduler": | ||
filename = define.SCHEDULER_LOG_FILE; | ||
break; | ||
case "operator": | ||
filename = define.OPERATOR_LOG_FILE; | ||
break; | ||
} | ||
|
||
if (!fs.existsSync(filename)) { | ||
response.head(204); | ||
response.end(''); | ||
return; | ||
} | ||
|
||
response.head(200); | ||
|
||
response.write(new Array(1024).join(' ')); | ||
|
||
var tailf = child_process.spawn('tail', ['-f', '-n', '100', filename]); | ||
children.push(tailf.pid); | ||
|
||
tailf.stdout.pipe(response); | ||
|
||
tailf.on('exit', function(code) { | ||
response.end(); | ||
}); | ||
|
||
request.on('close', function() { | ||
tailf.kill('SIGKILL'); | ||
}); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,37 @@ | ||
(function() { | ||
|
||
if (['wui', 'operator', 'scheduler'].indexOf(request.param.name) === -1) { | ||
return response.error(404); | ||
} | ||
|
||
var filename = './log/' + request.param.name; | ||
|
||
if (!fs.existsSync(filename)) { | ||
response.head(204); | ||
response.end(''); | ||
return; | ||
} | ||
|
||
response.head(200); | ||
|
||
fs.readFile(filename, function(err, data) { | ||
if (err) { | ||
util.log(err); | ||
return response.error(500); | ||
} | ||
|
||
response.end(data); | ||
}); | ||
|
||
(function() { | ||
|
||
if (['wui', 'operator', 'scheduler'].indexOf(request.param.name) === -1) { | ||
return response.error(404); | ||
} | ||
|
||
let filename = ""; | ||
switch (request.param.name) { | ||
case "wui": | ||
filename = define.WUI_LOG_FILE; | ||
break; | ||
case "scheduler": | ||
filename = define.SCHEDULER_LOG_FILE; | ||
break; | ||
case "operator": | ||
filename = define.OPERATOR_LOG_FILE; | ||
break; | ||
} | ||
|
||
if (!fs.existsSync(filename)) { | ||
response.head(204); | ||
response.end(''); | ||
return; | ||
} | ||
|
||
response.head(200); | ||
|
||
fs.readFile(filename, function(err, data) { | ||
if (err) { | ||
util.log(err); | ||
return response.error(500); | ||
} | ||
|
||
response.end(data); | ||
}); | ||
|
||
})(); |