|
@@ -97,13 +97,18 @@ function init() {
|
|
|
logger.info(`访问-日志相对目录:${logPath}`)
|
|
|
// 将相对路径转换为绝对路径
|
|
|
const directoryPath = path.resolve(logPath);
|
|
|
- file.checkPathSync(directoryPath)
|
|
|
- file.getLastFile(logPath, 10, (fileNameList) => {
|
|
|
- // logger.info('??1:', fileNameList);
|
|
|
- result = file.readLastNLines(logPath, fileNameList, n);
|
|
|
- // logger.info('?????:', result);
|
|
|
- res.send({'code': 200, 'data': result, "message": "SUCCESS"});
|
|
|
- });
|
|
|
+ try {
|
|
|
+ file.checkPathSync(directoryPath)
|
|
|
+ file.getLastFile(logPath, 10, (fileNameList) => {
|
|
|
+ // logger.info('??1:', fileNameList);
|
|
|
+ result = file.readLastNLines(logPath, fileNameList, n);
|
|
|
+ // logger.info('?????:', result);
|
|
|
+ res.send({'code': 200, 'data': result, "message": "SUCCESS"});
|
|
|
+ });
|
|
|
+ }catch (e) {
|
|
|
+ logger.info('获取日志异常了~~', e);
|
|
|
+ res.send({'code': 200, 'data': [], "message": "SUCCESS"});
|
|
|
+ }
|
|
|
} else {
|
|
|
res.send({'code': 200, 'data': result, "message": "SUCCESS"});
|
|
|
}
|