Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to overload console? #11

Closed
TotallyInformation opened this issue Apr 21, 2016 · 6 comments
Closed

Is it possible to overload console? #11

TotallyInformation opened this issue Apr 21, 2016 · 6 comments

Comments

@TotallyInformation
Copy link

I have a complex application (Node-Red) that logs to stdout using console and I would love to be able to redirect that output to storyboard since it runs on a raspberry pi that is tucked away somewhere remote. It would be much easier to debug things and monitor log output if I could use storyboard to do it. But, I obviously cannot dig into the Node-Red code and change all of the console outputs.

@guigrpa
Copy link
Owner

guigrpa commented Apr 22, 2016

In Linux/Raspbian, you can pipe the output of your program to a simple logger.js script as follows:

$ ./myProgram |& node logger

(using |& to connect both stdout and stderr to the logger). And in logger.js:

var split = require('split');
var mainStory = require('storyboard').mainStory;

process.stdin.pipe(split())
  .on('data', function(line) { mainStory.info(line); })
  .on('end', function() { process.exit(0); });

I'm using here the split package to read stdin line by line and pass it to Storyboard's mainStory for logging. You may want to parse the input line to determine its level (whether it should be written as debug, info, warn, error, etc.) and source, which would be useful for filtering.

Example output:

$ ls |& node logger
2016-04-22T05:43:23.238Z           storyboard INFO  ┌── ROOT STORY: Node.js 5.4.1 on Linux 64-bit [CREATED]
2016-04-22T05:43:23.249Z                 main INFO  logger.js
2016-04-22T05:43:23.250Z                 main INFO  node_modules
2016-04-22T05:43:23.250Z                 main INFO  package.json
2016-04-22T05:43:23.250Z                 main INFO  src
2016-04-22T05:43:23.250Z                 main INFO  test
2016-04-22T05:43:23.251Z                 main INFO
2016-04-22T05:43:23.252Z           storyboard INFO  └── ROOT STORY: Node.js 5.4.1 on Linux 64-bit [CLOSED]
$ missingCommand |& node logger
2016-04-22T05:43:37.035Z           storyboard INFO  ┌── ROOT STORY: Node.js 5.4.1 on Linux 64-bit [CREATED]
2016-04-22T05:43:37.046Z                 main INFO  missingCommand: command not found
2016-04-22T05:43:37.048Z                 main INFO
2016-04-22T05:43:37.048Z           storyboard INFO  └── ROOT STORY: Node.js 5.4.1 on Linux 64-bit [CLOSED]

Please tell me if it works for you!

@guigrpa
Copy link
Owner

guigrpa commented May 2, 2016

Closing this now. Please reopen if the solution is not sufficient

@guigrpa guigrpa closed this as completed May 2, 2016
guigrpa added a commit that referenced this issue May 2, 2016
@guigrpa
Copy link
Owner

guigrpa commented May 2, 2016

Included the logger tool in the library, under lib/stdinLogger.js (src: src/stdinLogger.coffee).

@TotallyInformation
Copy link
Author

Thanks.

@guigrpa
Copy link
Owner

guigrpa commented Jul 19, 2016

Just FYI, Storyboard version 2.0 includes a revamped CLI tool that handles not only stdout, but also stderr and stdin. In fact, you can even wrap a whole shell like this: sb --server sh.

@TotallyInformation
Copy link
Author

Thanks Guillermo, I'll check it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants