netlify-cli 17.5.3 → 17.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "netlify-cli",
3
- "version": "17.5.3",
3
+ "version": "17.6.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "netlify-cli",
9
- "version": "17.5.3",
9
+ "version": "17.6.0",
10
10
  "hasInstallScript": true,
11
11
  "license": "MIT",
12
12
  "dependencies": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "netlify-cli",
3
3
  "description": "Netlify command line tool",
4
- "version": "17.5.3",
4
+ "version": "17.6.0",
5
5
  "author": "Netlify Inc.",
6
6
  "type": "module",
7
7
  "engines": {
@@ -1,17 +1,28 @@
1
- import { Argument } from 'commander';
1
+ import { Argument, Option } from 'commander';
2
2
  import inquirer from 'inquirer';
3
3
  import { chalk, log } from '../../utils/command-helpers.mjs';
4
4
  import { getWebSocket } from '../../utils/websockets/index.mjs';
5
+ // Source: Source: https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-advanced
6
+ export const LOG_LEVELS = {
7
+ TRACE: 'TRACE',
8
+ DEBUG: 'DEBUG',
9
+ INFO: 'INFO',
10
+ WARN: 'WARN',
11
+ ERROR: 'ERROR',
12
+ FATAL: 'FATAL',
13
+ };
14
+ const LOG_LEVELS_LIST = Object.values(LOG_LEVELS).map((level) => level.toLowerCase());
15
+ const CLI_LOG_LEVEL_CHOICES_STRING = LOG_LEVELS_LIST.map((level) => ` ${level}`);
5
16
  function getLog(logData) {
6
17
  let logString = '';
7
18
  switch (logData.level) {
8
- case 'INFO':
19
+ case LOG_LEVELS.INFO:
9
20
  logString += chalk.blueBright(logData.level);
10
21
  break;
11
- case 'WARN':
22
+ case LOG_LEVELS.WARN:
12
23
  logString += chalk.yellowBright(logData.level);
13
24
  break;
14
- case 'ERROR':
25
+ case LOG_LEVELS.ERROR:
15
26
  logString += chalk.redBright(logData.level);
16
27
  break;
17
28
  default:
@@ -24,6 +35,10 @@ const logsFunction = async (functionName, options, command) => {
24
35
  const client = command.netlify.api;
25
36
  const { site } = command.netlify;
26
37
  const { id: siteId } = site;
38
+ if (options.level && !options.level.every((level) => LOG_LEVELS_LIST.includes(level))) {
39
+ log(`Invalid log level. Choices are:${CLI_LOG_LEVEL_CHOICES_STRING}`);
40
+ }
41
+ const levelsToPrint = options.level || LOG_LEVELS_LIST;
27
42
  const { functions = [] } = await client.searchSiteFunctions({ siteId });
28
43
  if (functions.length === 0) {
29
44
  log(`No functions found for the site`);
@@ -58,6 +73,9 @@ const logsFunction = async (functionName, options, command) => {
58
73
  });
59
74
  ws.on('message', (data) => {
60
75
  const logData = JSON.parse(data);
76
+ if (!levelsToPrint.includes(logData.level.toLowerCase())) {
77
+ return;
78
+ }
61
79
  log(getLog(logData));
62
80
  });
63
81
  ws.on('close', () => {
@@ -71,7 +89,12 @@ const logsFunction = async (functionName, options, command) => {
71
89
  export const createLogsFunctionCommand = (program) => program
72
90
  .command('logs:function')
73
91
  .alias('logs:functions')
92
+ .addOption(new Option('-l, --level <levels...>', `Log levels to stream. Choices are:${CLI_LOG_LEVEL_CHOICES_STRING}`))
74
93
  .addArgument(new Argument('[functionName]', 'Name of the function to stream logs for'))
75
- .addExamples(['netlify logs:function my-function', 'netlify logs:function'])
94
+ .addExamples([
95
+ 'netlify logs:function',
96
+ 'netlify logs:function my-function',
97
+ 'netlify logs:function my-function -l info warn',
98
+ ])
76
99
  .description('(Beta) Stream netlify function logs to the console')
77
100
  .action(logsFunction);