Skip to content

Commit 8f793ae

Browse files
fix: Improve logger
1 parent 1e2b3fc commit 8f793ae

File tree

7 files changed

+121
-23
lines changed

7 files changed

+121
-23
lines changed

package-lock.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"@aws-sdk/client-s3": "^3.577.0",
9292
"@aws-sdk/credential-providers": "^3.577.0",
9393
"aws-iot-device-sdk": "^2.2.13",
94+
"chalk": "^5.3.0",
9495
"chokidar": "^3.6.0",
9596
"commander": "^12.0.0",
9697
"esbuild": "^0.20.1",
@@ -117,7 +118,8 @@
117118
"yaml",
118119
"typescript",
119120
"inquirer",
120-
"jsonc-parser"
121+
"jsonc-parser",
122+
"chalk"
121123
],
122124
"workspaces": [
123125
"src/extension/*",

src/configuration/getConfigFromWizard.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,18 +347,31 @@ async function saveConfiguration(config: LldConfigCliArgs) {
347347
import { type LldConfigTs } from "lambda-live-debugger";
348348
349349
export default {
350+
// Framework to use
350351
framework: "${config.framework}",
352+
// AWS CDK context
351353
context: ${config.context ? JSON.stringify(config.context) : undefined},
354+
// Serverless Framework stage
352355
stage: "${config.stage}",
356+
// Monorepo subfolder
353357
subfolder: "${config.subfolder}",
358+
// Filter by function name. You can use * as a wildcard
354359
function: "${config.function}",
360+
// AWS profile
355361
profile: "${config.profile}",
362+
// AWS region
356363
region: "${config.region}",
364+
// AWS role
357365
role: "${config.role}",
366+
// SAM environment
358367
configEnv: "${config.configEnv}",
368+
// Observable mode
359369
observable: ${config.observable},
370+
// Observable mode interval
360371
interval: ${config.interval === defaultObservableInterval ? undefined : config.interval},
372+
// Verbose logs
361373
verbose: ${config.verbose},
374+
// Modify Lambda function list or support custom framework
362375
//getLambdas: async (foundLambdas) => {
363376
// you can customize the list of lambdas here or create your own
364377
// return foundLambdas;

src/lambdaConnection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async function onMessageFromLambda(message: IoTMessage) {
6868
}
6969

7070
if (Configuration.config.verbose) {
71-
Logger.verbose(
71+
Logger.log(
7272
`[Function ${message.data.functionId}] Response: `,
7373
JSON.stringify(message.data, null, 2),
7474
);
@@ -85,7 +85,7 @@ async function onMessageFromLambda(message: IoTMessage) {
8585
const response = await NodeHandler.invokeLambda(message.data);
8686

8787
if (Configuration.config.verbose) {
88-
Logger.verbose(
88+
Logger.log(
8989
`[Function ${message.data.functionId}] Response: `,
9090
JSON.stringify(response, null, 2),
9191
);

src/lldebugger.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function run() {
2424
const version = await getVersion();
2525

2626
Logger.log(`Welcome to Lambda Live Debugger 🐞 version ${version}.`);
27-
Logger.log(
27+
Logger.important(
2828
'To keep the project moving forward, please fill out the feedback form at https://forms.gle/v6ekZtuB45Rv3EyW9. Your input is greatly appreciated!',
2929
);
3030

@@ -57,8 +57,7 @@ async function run() {
5757
Configuration.config.observable
5858
? 'in observable mode'
5959
: `(ID ${Configuration.config.debuggerId})`
60-
}
61-
...`,
60+
}...`,
6261
);
6362

6463
if (Configuration.config.subfolder) {

src/logger.mjs

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,63 @@
1+
// @ts-nocheck
2+
import chalk from 'chalk';
3+
const orange = '#D24E01';
14
let verboseEnabled = false;
25
/**
3-
* Log verbose message in verbose logging is enabled
4-
* @param args
6+
* Log a message
7+
* @param args The arguments to log
8+
*/
9+
function log(...args) {
10+
args = args.map((arg) => {
11+
if (typeof arg === 'string') {
12+
// Regular expression to find text within square brackets
13+
return arg.replace(/\[(.*?)\]/g, (match) => chalk.gray(match)); // Colorizes the entire bracketed content
14+
}
15+
return arg;
16+
});
17+
console.log(...args);
18+
}
19+
/**
20+
* Log an important message
21+
* @param args The arguments to log
22+
*/
23+
function important(...args) {
24+
console.log(chalk.hex(orange)(...args));
25+
}
26+
/**
27+
* Log an error message in red
28+
* @param args The arguments to log
29+
*/
30+
function error(...args) {
31+
console.error(chalk.red(...args));
32+
}
33+
/**
34+
* Log a warning message in orange
35+
* @param args The arguments to log
36+
*/
37+
function warn(...args) {
38+
console.warn(chalk.hex(orange)(...args));
39+
}
40+
/**
41+
* Log a verbose message if verbose is enabled. Log the message in grey.
42+
* @param args The arguments to log
543
*/
644
function verbose(...args) {
745
if (verboseEnabled) {
8-
console.info(...args);
46+
console.info(chalk.grey(...args));
947
}
1048
}
1149
/**
12-
*
13-
* @param enabled
50+
* Set the verbosity of logging
51+
* @param enabled Whether verbose logging should be enabled
1452
*/
1553
function setVerbose(enabled) {
1654
verboseEnabled = enabled;
1755
}
1856
export const Logger = {
19-
log: console.log,
20-
error: console.error,
21-
warn: console.warn,
57+
log,
58+
error,
59+
warn,
60+
important,
2261
verbose,
2362
setVerbose,
2463
};

src/logger.ts

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,70 @@
1+
import chalk from 'chalk';
2+
3+
const orange = '#D24E01';
14
let verboseEnabled = false;
25

36
/**
4-
* Log verbose message in verbose logging is enabled
5-
* @param args
7+
* Log a message
8+
* @param args The arguments to log
9+
*/
10+
function log(...args: any[]) {
11+
args = args.map((arg) => {
12+
if (typeof arg === 'string') {
13+
// Regular expression to find text within square brackets
14+
return arg.replace(/\[(.*?)\]/g, (match) => chalk.gray(match)); // Colorizes the entire bracketed content
15+
}
16+
return arg;
17+
});
18+
console.log(...args);
19+
}
20+
21+
/**
22+
* Log an important message
23+
* @param args The arguments to log
24+
*/
25+
function important(...args: any[]) {
26+
console.log(chalk.hex(orange)(...args));
27+
}
28+
29+
/**
30+
* Log an error message in red
31+
* @param args The arguments to log
32+
*/
33+
function error(...args: any[]) {
34+
console.error(chalk.red(...args));
35+
}
36+
37+
/**
38+
* Log a warning message in orange
39+
* @param args The arguments to log
40+
*/
41+
function warn(...args: any[]) {
42+
console.warn(chalk.hex(orange)(...args));
43+
}
44+
45+
/**
46+
* Log a verbose message if verbose is enabled. Log the message in grey.
47+
* @param args The arguments to log
648
*/
749
function verbose(...args: any[]) {
850
if (verboseEnabled) {
9-
console.info(...args);
51+
console.info(chalk.grey(...args));
1052
}
1153
}
1254

1355
/**
14-
*
15-
* @param enabled
56+
* Set the verbosity of logging
57+
* @param enabled Whether verbose logging should be enabled
1658
*/
1759
function setVerbose(enabled: boolean) {
1860
verboseEnabled = enabled;
1961
}
2062

2163
export const Logger = {
22-
log: console.log,
23-
error: console.error,
24-
warn: console.warn,
64+
log,
65+
error,
66+
warn,
67+
important,
2568
verbose,
2669
setVerbose,
2770
};

0 commit comments

Comments
 (0)