Skip to content
This repository was archived by the owner on Dec 20, 2017. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/avoscloud
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,13 @@ if(CMD) {
break;

case 'logs':
var prod = ["stg", "prod"].indexOf(program.env);
if (prod < 0) {
console.log("请使用:avoscloud logs -e <prod|stg> 查询指定环境的日志");
process.exit(1);
}
run.logProjectHome();
run.viewCloudLog(program.lines, program.tailf, null, callback);
run.viewCloudLog(program.lines, program.tailf, prod, null, callback);
break;

case "upload":
Expand Down
1 change: 1 addition & 0 deletions bin/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ exports.parse_args = function(argv){
.option('-o, --log <log>', '本次部署的提交日志,仅对从本地部署有效。')
.option('-n, --lines <lines>', '查看多少行最新的云代码日志,默认 10 行。', 10)
.option('-t, --tailf', '自动刷新云代码日志,结合 logs 命令使用。', 1)
.option('-e, --env <prod|stg>', '查看 prod 环境日志或 stg 环境,默认 prod 环境。', 'prod')
.option('-r, --revision <revision>', 'git 的版本号,仅对从 git 仓库部署有效。')
.option('-P, --port <port>', '指定本地调试的端口,默认 3000。', 3000)
.parse(argv);
Expand Down
8 changes: 4 additions & 4 deletions bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,19 +432,19 @@ function outputLogs(resp) {
if (resp && resp.length > 0) {
resp.reverse().forEach(function(log) {
var time = new Date(log.time).toLocaleString();
var env = log.production == 1 ? 'PROD' : 'TEST';
var env = log.production == 1 ? 'PROD' : 'STG';
var content = log.content.replace(/\n$/, '');
console.log('%s [%s] [%s] %s', time, env, log.level.toLocaleUpperCase(), content);
});
}
}

exports.viewCloudLog = function (lines, tailf, lastLogUpdatedTime, cb) {
exports.viewCloudLog = function (lines, tailf, prod, lastLogUpdatedTime, cb) {
initAVOSCloudSDK(function() {
var doViewCloudLog = function doViewCloudLog(lines, tailf, lastLogUpdatedTime, cb) {
var url = 'tables/EngineLogs';
var url = 'tables/EngineLogs?production=' + prod;
if (lastLogUpdatedTime) {
url += '?since=' + encodeURIComponent(lastLogUpdatedTime);
url += '&since=' + encodeURIComponent(lastLogUpdatedTime);
}
util.requestCloud(url, {}, 'GET', {
success: function(resp) {
Expand Down