Add winston logger for different verbosity level

pull/7/head
0mkar 6 years ago
parent 2c5e455446
commit 417b3c81a6
  1. 3
      remix-tests/package.json
  2. 1
      remix-tests/src/index.js
  3. 58
      remix-tests/src/logger.js
  4. 43
      remix-tests/src/run.js

@ -46,7 +46,8 @@
"signale": "^1.2.1", "signale": "^1.2.1",
"solc": "^0.4.24", "solc": "^0.4.24",
"standard": "^10.0.3", "standard": "^10.0.3",
"web3": "1.0.0-beta.27" "web3": "1.0.0-beta.27",
"winston": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
"mocha": "^5.1.0" "mocha": "^5.1.0"

@ -12,7 +12,6 @@ const Web3 = require('web3')
const Provider = require('remix-simulator').Provider const Provider = require('remix-simulator').Provider
var createWeb3Provider = function () { var createWeb3Provider = function () {
signale.info('Creating providers')
let web3 = new Web3() let web3 = new Web3()
web3.setProvider(new Provider()) web3.setProvider(new Provider())
return web3 return web3

@ -0,0 +1,58 @@
var gray = require('ansi-gray')
const winston = require('winston')
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
}
function getTimestamp () {
return '[' + addColor(timestamp('HH:mm:ss')) + ']'
}
// create winston logger format
const logFmt = winston.format.printf((info) => {
return `${getTimestamp()} ${info.level}: ${info.message}`
})
class Log {
constructor () {
this.logger = winston.createLogger({
level: 'error',
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.colorize({ all: true }),
logFmt
)
})
}
setVerbosity (v) {
this.logger.configure({
level: v,
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.colorize({ all: true }),
logFmt
)
})
}
}
module.exports = {
Log
}

@ -2,24 +2,37 @@ const commander = require('commander')
const Web3 = require('web3') const Web3 = require('web3')
const RemixTests = require('./index.js') const RemixTests = require('./index.js')
const fs = require('fs') const fs = require('fs')
const { Signale } = require('signale')
const Provider = require('remix-simulator').Provider const Provider = require('remix-simulator').Provider
const { Log } = require('./logger.js')
const logger = new Log()
const log = logger.logger
require('colors') require('colors')
// signale configuration // parse verbosity
const options = { function mapVerbosity (v) {
types: { const levels = {
greet: { 0: 'error',
badge: '\n👁', 1: 'warn',
label: '', 2: 'info',
color: 'yellow' 3: 'verbose',
} 4: 'debug',
5: 'silly'
} }
return levels[v]
} }
const signale = new Signale(options) // get current version
const pjson = require('../package.json')
commander.action(function (filename) { commander
signale.greet(('Running remix-tests: Unit testing for solidity.\n').yellow) .version(pjson.version)
.option('-v, --verbose <level>', 'run with verbosity', mapVerbosity)
.action(function (filename) {
// Console message
console.log(('\n\t👁 :: Running remix-tests - Unit testing for solidity :: 👁\t\n').white)
// set logger verbosity
if (commander.verbose) {
logger.setVerbosity(commander.verbose)
log.info('verbosity level set to ' + commander.verbose.blue)
}
let web3 = new Web3() let web3 = new Web3()
// web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) // web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))
web3.setProvider(new Provider()) web3.setProvider(new Provider())
@ -27,10 +40,10 @@ commander.action(function (filename) {
let isDirectory = fs.lstatSync(filename).isDirectory() let isDirectory = fs.lstatSync(filename).isDirectory()
RemixTests.runTestFiles(filename, isDirectory, web3) RemixTests.runTestFiles(filename, isDirectory, web3)
}) })
if (!process.argv.slice(2).length) { if (!process.argv.slice(2).length) {
signale.fatal('Please specify a filename') log.error('Please specify a filename')
process.exit() process.exit()
} }

Loading…
Cancel
Save