mantoni / brout.js Goto Github PK
View Code? Open in Web Editor NEWstdout and stderr for browsers
License: MIT License
stdout and stderr for browsers
License: MIT License
Hi, this is really cool, I'm a big fan of isomorphic code and yours is super elegant...
I noticed small issue though: when there are no listeners, stdout
always writes to info
and stderror
to warn
instead of log
and error
respectively. I figured out why...
Take log
and info
for example.
because you did this
console.info = console.log
when you do this
console.log.original = originalLog;
console.info.original = originalInfo;
your actually doing this
console.log.original = originalLog;
console.log.original = originalInfo;
because console.info
is already console.log
, so the .original
member resolves to console.log.original
. That's why stdout
is logging to the info
channel.
The easy fix is to replace this code
redirectLog('log', 'stdout');
redirectLog('warn', 'stderr');
console.info = console.log;
console.error = console.warn;
with this
redirectLog('log', 'stdout');
redirectLog('info', 'stdout');
redirectLog('warn', 'stderr');
redirectLog('error', 'stderr');
... if you want to keep that functionality.
For me I would prefer to keep the info
and warn
channels free since, technically, they don't map onto node. Therefore I would suggest this...
redirectLog('log', 'stdout');
redirectLog('error', 'stderr');
When I was testing using your mocaccino, I realised that, if the logs are already rewired before the code hits the test, console.xxx.original will already point to process.write
which will cause a stack overflow.
Suggested fix in brout is:
var originalLog = console.log.original || console.log;
var originalInfo = console.info.original || console.info;
var originalWarn = console.warn.original || console.warn;
var originalError = console.error.original || console.error;
As long as the outer code also has this patch, you will always get the correct logger.
its nothing amazing, but i thought i'd share
https://github.com/kumavis/browser-stdout
cheers ๐ป
The formatting of the stack traces do not like /?=^\s+at\s+/
, they are actually like /^.*@http:\/\/.+/
This is causing the final test to fail.
Hi, just to follow up on my comment in the PR...
./test/*.js
is not resolved when I run this in windows so npm throws.
I had to change it to ./test/brout-test.js.
Hi @mantoni . I do exactly the readme case:
myscript.js:
process.stdout.write('Hello stdout!\n');
console.log('Hello %s!', 'console');
$ browserify -t brout test/myscript.js | phantomic
And get this error:
TypeError: 'undefined' is not an object (evaluating 'process.stdout.write')
at http://localhost:55036/js/bundle:91
at http://localhost:55036/js/bundle:93
at http://localhost:55036/js/bundle:1
at http://localhost:55036/js/bundle:1
at http://localhost:55036/js/bundle:94
Seems that that mishap breaks macoccino and mochify: mantoni/mochify.js#54
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.