zapier-platform-cli
Version:
The CLI for apps in the Zapier Developer Platform.
58 lines (48 loc) • 5.97 kB
JavaScript
'use strict';
var utils = require('../utils');
var colors = require('colors/safe');
var logs = function logs(context) {
context.line('The logs of your app listed below.\n');
utils.startSpinner();
return utils.listLogs(global.argOpts).then(function (data) {
utils.endSpinner('');
var columns = void 0;
var type = global.argOpts.type || logs.argOptsSpec.type.default;
if (type === 'http') {
columns = [['Status', 'response_status_code'], ['Method', 'request_method'], ['URL', 'request_url'], ['Querystring', 'request_params'], ['Version', 'app_cli_version'], ['Step ID', 'step'],
// ['ID', 'id'],
['Timestamp', 'timestamp']];
if (global.argOpts.detailed) {
columns.push(['Request Headers', 'request_headers']);
columns.push(['Request Body', 'request_data']);
columns.push(['Response Headers', 'response_headers']);
columns.push(['Response Body', 'response_content']);
}
} else {
columns = [['Log', 'full_message'], ['Version', 'app_cli_version'], ['Step', 'step'],
// ['ID', 'id'],
['Timestamp', 'timestamp']];
}
var ifEmpty = colors.grey('No logs found. Try adding some `z.request()`, `z.console.log()` and doing a `zapier push`!\n');
var listLogs = [].concat(data.logs);
listLogs.reverse();
utils.printData(listLogs, columns, ifEmpty, true);
context.line(colors.grey(' Most recent logs near the bottom.'));
if (type === 'http' && !global.argOpts.detailed) {
context.line(colors.grey(' TIP: Use `zapier logs --type=http --detailed` to include response information.'));
}
});
};
logs.argsSpec = [];
logs.argOptsSpec = {
version: { help: 'display only this version\'s logs (default is all versions)' },
status: { help: 'display only success logs (status code < 400 / info) or error (status code > 400 / tracebacks)', choices: ['any', 'success', 'error'], default: 'any' },
type: { help: 'display only console or http logs', choices: ['console', 'http'], default: 'console' },
detailed: { help: 'show detailed logs (like request/response body and headers)', flag: true },
user: { help: 'display only this user\'s logs', example: 'user@example.com', 'default': 'me' },
limit: { help: 'control the maximum result size', default: 50 }
};
logs.help = 'Prints recent logs. See help for filter arguments.';
logs.example = 'zapier logs';
logs.docs = '\nGet the logs that are automatically collected during the running of your app. Either explicitly during `z.console.log()`, automatically via `z.request()`, or any sort of traceback or error.\n\n> Does not collect or list the errors found locally during `zapier test`.\n\n**Arguments**\n\n' + utils.argsFragment(logs.argsSpec) + '\n' + utils.argOptsFragment(logs.argOptsSpec) + '\n' + utils.defaultArgOptsFragment() + '\n\n' + '```' + 'bash\n$ zapier logs\n# The logs of your app "Example" listed below.\n#\n# \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n# \u2502 = 1 = \u2502\n# \u2502 Log \u2502 console says hello world! \u2502\n# \u2502 Version \u2502 1.0.0 \u2502\n# \u2502 Step \u2502 99c16565-1547-4b16-bcb5-45189d9d8afa \u2502\n# \u2502 Timestamp \u2502 2016-01-01T23:04:36-05:00 \u2502\n# \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n\n$ zapier logs --type=http\n# The logs of your app "Example" listed below.\n#\n# \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n# \u2502 = 1 = \u2502\n# \u2502 Status \u2502 200 \u2502\n# \u2502 URL \u2502 http://httpbin.org/get \u2502\n# \u2502 Querystring \u2502 hello=world \u2502\n# \u2502 Version \u2502 1.0.0 \u2502\n# \u2502 Step \u2502 99c16565-1547-4b16-bcb5-45189d9d8afa \u2502\n# \u2502 Timestamp \u2502 2016-01-01T23:04:36-05:00 \u2502\n# \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n\n$ zapier logs --type=http --detailed --format=plain\n# The logs of your app "Example" listed below.\n#\n# == Status\n# 200\n# == URL\n# http://httpbin.org/get\n# == Querystring\n# hello=world\n# == Version\n# 1.0.0\n# == Step\n# 99c16565-1547-4b16-bcb5-45189d9d8afa\n# == Timestamp\n# 2016-08-03T23:04:36-05:00\n# == Request Body\n# == Response Body\n# {\n# "args": {\n# "hello": "world"\n# },\n# "headers": {\n# "Accept": "*/*",\n# "Accept-Encoding": "gzip,deflate",\n# "Host": "httpbin.org",\n# "User-Agent": "Zapier"\n# },\n# "origin": "123.123.123.123",\n# "url": "http://httpbin.org/get?hello=world"\n# }\n' + '```' + '\n';
module.exports = logs;