Skip to content

Commit 69970be

Browse files
author
zidong.pei
committed
Complete ES6 verification
Complete ES6 verification Complete ES6 verification fix inexist error logs test install alinode shell Add executable permission Add executable permission Add executable permission back Add executable permission back Add executable permission change bash to sh change bash to sh Use wget download tnvm Use wget download tnvm source .bashrc Rollback system test echo TRAVIS_NODE_VERSION Install alinode according to the node version Install alinode according to the node version Install alinode according to the node version which node Add wildcard match log test
1 parent 1502e46 commit 69970be

File tree

5 files changed

+94
-32
lines changed

5 files changed

+94
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ config_*.json
88
core.*
99
coredump_*
1010
.nyc_output/
11+
.vscode

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ node_js:
44
- "6"
55
- "8"
66
- "10"
7-
script: npm run ci
7+
script:
8+
- npm run ci
9+
10+
before_install:
11+
- ./install_alinode.sh

install_alinode.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
wget --no-check-certificate -O- https://raw.githubusercontent.com/aliyun-node/tnvm/master/install.sh | bash
2+
source $HOME/.bash_profile
3+
source $HOME/.bashrc
4+
echo TRAVIS_NODE_VERSION = $TRAVIS_NODE_VERSION
5+
6+
if [ $TRAVIS_NODE_VERSION -eq '6' ];then
7+
tnvm install alinode-v2.9.0
8+
tnvm use alinode-v2.9.0
9+
elif [ $TRAVIS_NODE_VERSION -eq '8' ];then
10+
tnvm install alinode-v3.16.0
11+
tnvm use alinode-v3.16.0
12+
elif [ $TRAVIS_NODE_VERSION -eq '10' ];then
13+
tnvm install alinode-v4.13.2
14+
tnvm use alinode-v4.13.2
15+
else
16+
tnvm install alinode-v6.4.4
17+
tnvm use alinode-v6.4.4
18+
fi
19+
20+
tnvm current
21+
22+
echo 'which node'
23+
which node
24+
25+
source $HOME/.bash_profile
26+
source $HOME/.bashrc
27+

lib/orders/error_log.js

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
var fs = require('fs');
44
var helper = require('../utils');
55
var Parser = require('../error_parser');
6-
const { promisify } = require('util');
7-
var glob = promisify(require('glob'));
6+
var glob = require('glob');
87

98
var MAX_ERROR_COUNT = 20; // 一次最多抓获20个Error
109
exports.logs = []; // 日志路径
@@ -13,12 +12,14 @@ var keyMap = new Map(); // 记录每个key实际对应的路径值
1312
var map = new Map(); // 记录每个文件访问的位置
1413
var parsers = new Map(); // 每个key都有一个parser
1514

16-
var getRealPath = async function (filepath) {
17-
var files = await glob(filepath)
18-
return files.map(path => helper.resolveYYYYMMDDHH(path))
19-
15+
var getRealPath = function (filepath,callback) {
16+
glob(filepath,callback);
2017
};
2118

19+
// var a = function (err,file){
20+
// return file.map(path => helper.resolveYYYYMMDDHH(path))
21+
// }
22+
2223
var readFile = function (key, filepath, callback) {
2324
fs.stat(filepath, function (err, stats) {
2425
if (err) {
@@ -66,27 +67,37 @@ var readFile = function (key, filepath, callback) {
6667
});
6768
};
6869

69-
var readLog = async function (key, callback) {
70-
var currentPaths = await getRealPath(key);
71-
var currents = keyMap.get(key);
72-
73-
if (currentPaths.toString() !== currents.toString()) {
74-
keyMap.set(key, currentPath); // replace real path
75-
currents.forEach(current => {
76-
readFile(key, current, function (err) {
77-
if (err) {
78-
return callback(err);
79-
}
70+
var readLog = function (key, callback) {
71+
getRealPath(key,function(_err,files){
72+
var currentPaths = files.map(path => helper.resolveYYYYMMDDHH(path));
73+
var currents = keyMap.get(key);
74+
75+
if (currentPaths.toString() !== currents.toString()) {
76+
keyMap.set(key, currentPaths); // replace real path
77+
currents.forEach(current => {
78+
readFile(key, current, function (err) {
79+
if (err) {
80+
return callback(err);
81+
}
82+
if( currentPaths.length !== 0) {
83+
currentPaths.forEach(path => {
84+
readFile(key, path, callback);
85+
});
86+
} else {
87+
readFile(key, '', callback);
88+
}
89+
});
90+
});
91+
} else {
92+
if( currentPaths.length !== 0) {
8093
currentPaths.forEach(path => {
8194
readFile(key, path, callback);
82-
})
83-
});
84-
})
85-
} else {
86-
currentPaths.forEach(path => {
87-
readFile(key, path, callback);
88-
})
89-
}
95+
});
96+
}else{
97+
readFile(key, '', callback);
98+
}
99+
}
100+
});
90101
};
91102

92103
var readLogs = function (callback) {
@@ -104,21 +115,25 @@ var readLogs = function (callback) {
104115
}
105116
};
106117

107-
exports.init = async function (config) {
118+
exports.init = function (config) {
108119
if (config.error_log) {
109120
exports.logs = config.error_log;
110121
var logs = config.error_log;
111122

112-
for (var i = 0; i < logs.length; i++) {
113-
var key = logs[i];
114-
parsers.set(key, new Parser(MAX_ERROR_COUNT));
115-
var realPath = await getRealPath(key);
123+
var key;
124+
var initCallBack = function(_err,files){
125+
var realPath = files.map(path => helper.resolveYYYYMMDDHH(path));
116126
realPath.forEach(path => {
117127
if (fs.existsSync(path)) {
118128
map.set(path, fs.statSync(path).size);
119129
}
120-
})
130+
});
121131
keyMap.set(key, realPath);
132+
};
133+
for (var i = 0; i < logs.length; i++) {
134+
key = logs[i];
135+
parsers.set(key, new Parser(MAX_ERROR_COUNT));
136+
getRealPath(key,initCallBack);
122137
}
123138
}
124139
};

test/orders/error_log.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ describe('/lib/orders/error_log.js', function () {
9595
});
9696
});
9797

98+
describe('wildcard match log', function () {
99+
before(function () {
100+
errorLog.init({
101+
error_log: [path.join(__dirname, '../logs', '*.log')]
102+
});
103+
});
104+
105+
it('should ok', function (done) {
106+
errorLog.run(function (err) {
107+
expect(err).to.not.be.ok();
108+
done();
109+
});
110+
});
111+
});
112+
98113
describe('when path is folder error logs', function () {
99114
before(function () {
100115
errorLog.init({

0 commit comments

Comments
 (0)