Skip to content

Commit

Permalink
feat: release initial roarr.io integration
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed May 1, 2021
1 parent 4d846de commit 0a5f911
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Roarr CLI program provides ability to filter and pretty-print [Roarr](https://github.com/gajus/roarr) logs.

* [Usage](#usage)
* [Viewing logs in browser](#viewing-logs-in-browser)
* [Filtering logs](#filtering-logs)
* [Formatting logs](#formatting-logs)
* [Roarr configuration file](#roarr-configuration-file)
Expand All @@ -23,20 +24,32 @@ Filters and formats Roarr log message.

Options:
--version Show version number [boolean]
--api-key roarr.io API key. [string]
--exclude-alien Excludes messages that cannot be recognized as
Roarr log message. [boolean] [default: false]
--filter-expression, --fe Roarr message filter expression.
--filter-expression, --fe Roarr message filter expression. [string]
--head When filtering, print a number of lines leading the
match. [number] [default: 2]
match. [number] [default: 0]
--lag When filtering, print a number of lines trailing
the match. [number] [default: 2]
the match. [number] [default: 0]
--output-format [choices: "pretty", "json"] [default: "pretty"]
--use-colors Toggle use of colors in the output.
[boolean] [default: true]
--help Show help [boolean]

```

### Viewing logs in browser

Configure `--api-key` to stream logs to https://roarr.io.

```bash
export ROARR_API_KEY=00000000-0000-0000-0000-000000000000

```

View logs by opening `https://roarr.io?room=[YOUR API KEY]`.

### Filtering logs

Use `--filter-expression` option to filter Roarr messages, e.g.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"prettyjson": "^1.2.1",
"roarr": "^3.2.0",
"searchjs": "^1.1.0",
"socket.io-client": "^4.0.1",
"split2": "^3.2.2",
"ulid": "^2.3.0",
"yargs": "^16.2.0"
Expand Down
28 changes: 28 additions & 0 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {
Instance as Chalk,
} from 'chalk';
import JSON5 from 'json5';
import {
io,
} from 'socket.io-client';
import split from 'split2';
import yargs from 'yargs';
import {
Expand All @@ -25,6 +28,16 @@ const argv = yargs
.env('ROARR')
.usage('Filters and formats Roarr log message.')
.options({
'api-key': {
description: 'roarr.io API key. Configuring API key automatically streams logs to roarr.io service.',
type: 'string',
},
'api-url': {
default: 'https://roarr.io',
description: 'roarr.io API URL.',
hidden: true,
type: 'string',
},
'exclude-alien': {
default: false,
description: 'Excludes messages that cannot be recognized as Roarr log message.',
Expand Down Expand Up @@ -81,8 +94,22 @@ const chalk = new Chalk({
level: argv['use-colors'] ? 3 : 0,
});

let socket;

if (argv['api-key']) {
socket = io(argv['api-url'], {
query: {
token: String(argv['api-key']),
},
});
}

let stream = process.stdin
.pipe(split((line) => {
if (socket) {
socket.emit('log', line);
}

if (!isRoarrLine(line)) {
return argv.excludeAlien ? '' : line + '\n';
}
Expand Down Expand Up @@ -111,3 +138,4 @@ if (argv['output-format'] === 'pretty') {
}

stream.pipe(process.stdout);

0 comments on commit 0a5f911

Please sign in to comment.