From db9bc985ebb47babbd1639d89c4a2590cb8412c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Mon, 4 Feb 2019 07:21:55 -0800 Subject: [PATCH] redirecting console to stderr Summary: Wrapping console to send all console.logs to stderr, as we are planning to use stdout for the actual data. By default only console.error messages are logged. I will add a `-v` argument to show all. Also, displaying some ASCII-art and the version number when starting flipper CLI. Reviewed By: passy Differential Revision: D13843675 fbshipit-source-id: acaa70d16f12965a8426abca506049dbafb7962c --- headless/index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/headless/index.js b/headless/index.js index dab3e590e..116b4852a 100644 --- a/headless/index.js +++ b/headless/index.js @@ -13,6 +13,26 @@ import path from 'path'; // $FlowFixMe this file exist, trust me, flow! import setup from '../static/setup.js'; +console.error(` + _____ _ _ +| __| |_|___ ___ ___ ___ +| __| | | . | . | -_| _| +|__| |_|_| _| _|___|_| v${global.__VERSION__} + |_| |_| +`); +// redirect all logging to stderr +const verboseMode = false; +const originalConsole = global.console; +global.console = new Proxy(console, { + get: function(obj, prop) { + return (...args) => { + if (prop === 'error' || verboseMode) { + originalConsole.error(`[${prop}] `, ...args); + } + }; + }, +}); + // Polyfills global.WebSocket = require('ws'); // used for redux devtools global.fetch = require('node-fetch/lib/index');