diff --git a/remix-simulator/package.json b/remix-simulator/package.json index fee69cf275..54ecf12a02 100644 --- a/remix-simulator/package.json +++ b/remix-simulator/package.json @@ -14,12 +14,15 @@ ], "main": "./index.js", "dependencies": { + "ansi-gray": "^0.1.1", + "babel-preset-es2017": "^6.24.1", "body-parser": "^1.18.2", + "color-support": "^1.1.3", "express": "^4.16.3", - "fancy-log": "^1.3.2", "merge": "^1.2.0", - "remix-lib": "latest", + "remix-lib": "^0.2.5", "standard": "^10.0.3", + "time-stamp": "^2.0.0", "web3": "1.0.0-beta.27" }, "scripts": { diff --git a/remix-simulator/src/provider.js b/remix-simulator/src/provider.js index e8ef2f3e77..6a4327f7b5 100644 --- a/remix-simulator/src/provider.js +++ b/remix-simulator/src/provider.js @@ -1,4 +1,4 @@ -const log = require('fancy-log') +const log = require('./utils/logs.js') const merge = require('merge') const Accounts = require('./methods/accounts.js') @@ -16,7 +16,6 @@ var Provider = function () { this.methods = merge(this.methods, (new Misc()).methods()) this.methods = merge(this.methods, (new Transactions(this.Accounts.accounts)).methods()) this.methods = merge(this.methods, (new Whisper()).methods()) - log.dir(this.methods) } Provider.prototype.sendAsync = function (payload, callback) { diff --git a/remix-simulator/src/server.js b/remix-simulator/src/server.js index 705d4a5dba..1171b8826d 100644 --- a/remix-simulator/src/server.js +++ b/remix-simulator/src/server.js @@ -2,7 +2,7 @@ const express = require('express') const bodyParser = require('body-parser') const app = express() const Provider = require('./provider') -const log = require('fancy-log') +const log = require('./utils/logs.js') var provider = new Provider() @@ -14,14 +14,10 @@ app.get('/', (req, res) => { }) app.use(function (req, res) { - // url, body, params, method - log('request ', req.method, req.body) provider.sendAsync(req.body, (err, jsonResponse) => { if (err) { res.send({error: err}) } - log.dir('response is ') - log.dir(jsonResponse) res.send(jsonResponse) }) }) diff --git a/remix-simulator/src/utils/logs.js b/remix-simulator/src/utils/logs.js new file mode 100644 index 0000000000..d117ea9fcb --- /dev/null +++ b/remix-simulator/src/utils/logs.js @@ -0,0 +1,81 @@ +'use strict'; + +var gray = require('ansi-gray'); +var timestamp = require('time-stamp'); +var supportsColor = require('color-support'); + +function hasFlag(flag) { + return ((typeof(process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1)); +} + +function addColor(str) { + if (hasFlag('no-color')) { + return str; + } + + if (hasFlag('color')) { + return gray(str); + } + + if (supportsColor()) { + return gray(str); + } + + return str; +} + +let logger = { + stdout: function(arg) { + if (typeof(process) === 'undefined' || !process.stdout) return; + process.stdout.write(arg); + }, + stderr: function(arg) { + if (typeof(process) === 'undefined' || process.stderr) return; + process.stderr.write(arg); + }, +}; + +function getTimestamp(){ + return '['+addColor(timestamp('HH:mm:ss'))+']'; +} + +function log(){ + var time = getTimestamp(); + logger.stdout(time + ' '); + console.log.apply(console, arguments); + return this; +} + +function info(){ + var time = getTimestamp(); + logger.stdout(time + ' '); + console.info.apply(console, arguments); + return this; +} + +function dir(){ + var time = getTimestamp(); + logger.stdout(time + ' '); + console.dir.apply(console, arguments); + return this; +} + +function warn(){ + var time = getTimestamp(); + logger.stderr(time + ' '); + console.warn.apply(console, arguments); + return this; +} + +function error(){ + var time = getTimestamp(); + logger.stderr(time + ' '); + console.error.apply(console, arguments); + return this; +} + +module.exports = log; +module.exports.info = info; +module.exports.dir = dir; +module.exports.warn = warn; +module.exports.error = error;