From ac52ad88a1884979c74f418398bbf428d727cf34 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 22 May 2018 10:39:27 -0700 Subject: Use loglevel instead of verbose flag --- packages/sol-cov/package.json | 8 +++++--- packages/sol-cov/src/coverage_manager.ts | 18 +++++++----------- yarn.lock | 6 +++++- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/sol-cov/package.json b/packages/sol-cov/package.json index e4d8c6da8..0edffb1d2 100644 --- a/packages/sol-cov/package.json +++ b/packages/sol-cov/package.json @@ -46,17 +46,18 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/sol-cov/README.md", "dependencies": { + "@0xproject/sol-compiler": "^0.4.3", "@0xproject/subproviders": "^0.10.2", "@0xproject/types": "^0.7.0", "@0xproject/typescript-typings": "^0.3.2", "@0xproject/utils": "^0.6.2", - "@0xproject/sol-compiler": "^0.4.3", "ethereumjs-util": "^5.1.1", - "rimraf": "^2.6.2", "glob": "^7.1.2", "istanbul": "^0.4.5", "lodash": "^4.17.4", + "loglevel": "^1.6.1", "mkdirp": "^0.5.1", + "rimraf": "^2.6.2", "semaphore-async-await": "^1.5.1", "solidity-parser-antlr": "^0.2.8" }, @@ -64,10 +65,11 @@ "@0xproject/monorepo-scripts": "^0.1.20", "@0xproject/tslint-config": "^0.4.18", "@types/istanbul": "^0.4.30", - "@types/rimraf": "^2.0.2", + "@types/loglevel": "^1.5.3", "@types/mkdirp": "^0.5.1", "@types/mocha": "^2.2.42", "@types/node": "^8.0.53", + "@types/rimraf": "^2.0.2", "chai": "^4.0.1", "copyfiles": "^1.2.0", "dirty-chai": "^2.0.1", diff --git a/packages/sol-cov/src/coverage_manager.ts b/packages/sol-cov/src/coverage_manager.ts index d7a00f86d..3aa62acff 100644 --- a/packages/sol-cov/src/coverage_manager.ts +++ b/packages/sol-cov/src/coverage_manager.ts @@ -3,6 +3,7 @@ import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util'; import * as fs from 'fs'; import { Collector } from 'istanbul'; import * as _ from 'lodash'; +import { getLogger, levels, Logger, LogLevel } from 'loglevel'; import * as mkdirp from 'mkdirp'; import * as path from 'path'; @@ -35,7 +36,7 @@ const mkdirpAsync = promisify(mkdirp); export class CoverageManager { private _artifactAdapter: AbstractArtifactAdapter; - private _verbose: boolean; + private _logger: Logger; private _traceInfos: TraceInfo[] = []; private _getContractCodeAsync: (address: string) => Promise; private static _getSingleFileCoverageForTrace( @@ -124,7 +125,7 @@ export class CoverageManager { } private static _getContractDataIfExists(contractsData: ContractData[], bytecode: string): ContractData | undefined { if (!bytecode.startsWith('0x')) { - throw new Error(')x missing'); + throw new Error('0x missing'); } const contractData = _.find(contractsData, contractDataCandidate => { const bytecodeRegex = CoverageManager._bytecodeToBytecodeRegex(contractDataCandidate.bytecode); @@ -142,7 +143,8 @@ export class CoverageManager { ) { this._getContractCodeAsync = getContractCodeAsync; this._artifactAdapter = artifactAdapter; - this._verbose = verbose; + this._logger = getLogger('sol-cov'); + this._logger.setLevel(verbose ? levels.TRACE : levels.ERROR); } public appendTraceInfo(traceInfo: TraceInfo): void { this._traceInfos.push(traceInfo); @@ -162,10 +164,7 @@ export class CoverageManager { const runtimeBytecode = (traceInfo as TraceInfoExistingContract).runtimeBytecode; const contractData = CoverageManager._getContractDataIfExists(contractsData, runtimeBytecode); if (_.isUndefined(contractData)) { - if (this._verbose) { - // tslint:disable-next-line:no-console - console.warn(`Transaction to an unknown address: ${traceInfo.address}`); - } + this._logger.warn(`Transaction to an unknown address: ${traceInfo.address}`); continue; } const bytecodeHex = stripHexPrefix(runtimeBytecode); @@ -190,10 +189,7 @@ export class CoverageManager { const bytecode = (traceInfo as TraceInfoNewContract).bytecode; const contractData = CoverageManager._getContractDataIfExists(contractsData, bytecode); if (_.isUndefined(contractData)) { - if (this._verbose) { - // tslint:disable-next-line:no-console - console.warn(`Unknown contract creation transaction`); - } + this._logger.warn(`Unknown contract creation transaction`); continue; } const bytecodeHex = stripHexPrefix(bytecode); diff --git a/yarn.lock b/yarn.lock index 98215f54b..42c4fa025 100644 --- a/yarn.lock +++ b/yarn.lock @@ -184,6 +184,10 @@ version "4.14.99" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.99.tgz#e6e10c0a4cc16c7409b3181f1e66880d2fb7d4dc" +"@types/loglevel@^1.5.3": + version "1.5.3" + resolved "https://registry.yarnpkg.com/@types/loglevel/-/loglevel-1.5.3.tgz#adfce55383edc5998a2170ad581b3e23d6adb5b8" + "@types/marked@0.0.28": version "0.0.28" resolved "https://registry.yarnpkg.com/@types/marked/-/marked-0.0.28.tgz#44ba754e9fa51432583e8eb30a7c4dd249b52faa" @@ -7081,7 +7085,7 @@ log-update@^1.0.2: ansi-escapes "^1.0.0" cli-cursor "^1.0.2" -loglevel@^1.4.1: +loglevel@^1.4.1, loglevel@^1.6.1: version "1.6.1" resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.1.tgz#e0fc95133b6ef276cdc8887cdaf24aa6f156f8fa" -- cgit v1.2.3