Add winston logger for different verbosity level

pull/7/head
0mkar 6 years ago
parent cf1cd8c077
commit 3891b5660e
  1. 3
      remix-tests/package.json
  2. 1
      remix-tests/src/index.js
  3. 58
      remix-tests/src/logger.js
  4. 55
      remix-tests/src/run.js

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

@ -12,7 +12,6 @@ const Web3 = require('web3')
const Provider = require('remix-simulator').Provider
var createWeb3Provider = function () {
signale.info('Creating providers')
let web3 = new Web3()
web3.setProvider(new Provider())
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,35 +2,48 @@ const commander = require('commander')
const Web3 = require('web3')
const RemixTests = require('./index.js')
const fs = require('fs')
const { Signale } = require('signale')
const Provider = require('remix-simulator').Provider
const { Log } = require('./logger.js')
const logger = new Log()
const log = logger.logger
require('colors')
// signale configuration
const options = {
types: {
greet: {
badge: '\n👁',
label: '',
color: 'yellow'
}
// parse verbosity
function mapVerbosity (v) {
const levels = {
0: 'error',
1: 'warn',
2: 'info',
3: 'verbose',
4: 'debug',
5: 'silly'
}
return levels[v]
}
const signale = new Signale(options)
commander.action(function (filename) {
signale.greet(('Running remix-tests: Unit testing for solidity.\n').yellow)
let web3 = new Web3()
// web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))
web3.setProvider(new Provider())
// web3.setProvider(new web3.providers.WebsocketProvider('ws://localhost:8546'))
// get current version
const pjson = require('../package.json')
commander
.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()
// web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))
web3.setProvider(new Provider())
// web3.setProvider(new web3.providers.WebsocketProvider('ws://localhost:8546'))
let isDirectory = fs.lstatSync(filename).isDirectory()
RemixTests.runTestFiles(filename, isDirectory, web3)
})
let isDirectory = fs.lstatSync(filename).isDirectory()
RemixTests.runTestFiles(filename, isDirectory, web3)
})
if (!process.argv.slice(2).length) {
signale.fatal('Please specify a filename')
log.error('Please specify a filename')
process.exit()
}

Loading…
Cancel
Save