暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

functions-log.js 1.6KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const opn = require("open");
  5. const qs = require("querystring");
  6. const command_1 = require("../command");
  7. const error_1 = require("../error");
  8. const cloudlogging = require("../gcp/cloudlogging");
  9. const functionsLog = require("../functions/functionslog");
  10. const projectUtils_1 = require("../projectUtils");
  11. const requirePermissions_1 = require("../requirePermissions");
  12. exports.command = new command_1.Command("functions:log")
  13. .description("read logs from deployed functions")
  14. .option("--only <function_names>", 'only show logs of specified, comma-seperated functions (e.g. "funcA,funcB")')
  15. .option("-n, --lines <num_lines>", "specify number of log lines to fetch")
  16. .option("--open", "open logs page in web browser")
  17. .before(requirePermissions_1.requirePermissions, ["logging.logEntries.list", "logging.logs.list"])
  18. .action(async (options) => {
  19. try {
  20. const projectId = (0, projectUtils_1.needProjectId)(options);
  21. const apiFilter = functionsLog.getApiFilter(options.only);
  22. if (options.open) {
  23. const url = `https://console.developers.google.com/logs/viewer?advancedFilter=${qs.escape(apiFilter)}&project=${projectId}`;
  24. opn(url);
  25. return;
  26. }
  27. const entries = await cloudlogging.listEntries(projectId, apiFilter, options.lines || 35, "desc");
  28. functionsLog.logEntries(entries);
  29. return entries;
  30. }
  31. catch (err) {
  32. throw new error_1.FirebaseError(`Failed to list log entries ${err.message}`, { exit: 1 });
  33. }
  34. });