Skip to content

Commit d174727

Browse files
committed
Add option for logging only the message
1 parent 5d846dc commit d174727

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ Pipe the CSV output into a markdown formatter for sharing with friends (using [`
6969
$ cwq --log-group MyLogGroup 'filter @type = "REPORT" | status max(@maxMemoryUsed / 1000 / 1000) as maxMemoryUsedMB by bin(5m)' | csvtomd
7070
```
7171

72+
Log only the message from the returne data (using `-m` or `--message-only`):
73+
74+
```bash
75+
$ cwq --message-only --logGroup MyLogGroup 'filter @message like /ERROR'
76+
```
77+
7278
### Log Group Matching
7379

7480
You can provide a glob expression to the `--log-group` argument to match log group names by prefix:

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cwq",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "A CLI for CloudWatch Logs Insights",
55
"author": "Brian Celenza",
66
"license": "Apache-2.0",

src/index.ts

+18-7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ const args = yargs
4141
default: 'now',
4242
description: 'When to end the search (duration or ISO 8601 format)',
4343
})
44+
.option('message-only', {
45+
alias: 'm',
46+
type: 'boolean',
47+
default: false,
48+
description: 'Return just the message in plain-text format (no CSV)',
49+
})
4450
.help()
4551
.alias('help', 'h').argv;
4652

@@ -150,14 +156,19 @@ process.on('SIGINT', async () => {
150156
}
151157

152158
// Output the results in the desired format
153-
switch (args.format) {
154-
case 'csv':
155-
console.log(new CsvParser().parse(results));
156-
break;
157-
case 'json':
158-
console.log(JSON.stringify(results));
159-
break;
159+
if (args['message-only']) {
160+
results.forEach((r) => console.log(r['@message']));
161+
} else {
162+
switch (args.format) {
163+
case 'csv':
164+
console.log(new CsvParser().parse(results));
165+
break;
166+
case 'json':
167+
console.log(JSON.stringify(results));
168+
break;
169+
}
160170
}
171+
161172
})().catch((e: Error) => {
162173
console.error(`Error: ${e.message}`);
163174
process.exit(1);

0 commit comments

Comments
 (0)