Added customizable log levels to quiet warnings (#379).
This commit is contained in:
parent
c88cb5ea90
commit
f3ec27b95f
|
@ -411,7 +411,6 @@ export class Contract {
|
||||||
if (address == null) { throw new Error('name not found'); }
|
if (address == null) { throw new Error('name not found'); }
|
||||||
return address;
|
return address;
|
||||||
}).catch((error: Error) => {
|
}).catch((error: Error) => {
|
||||||
console.log('ERROR: Cannot find Contract - ' + addressOrName);
|
|
||||||
throw error;
|
throw error;
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
|
@ -429,7 +428,7 @@ export class Contract {
|
||||||
if ((<any>this)[name] == null) {
|
if ((<any>this)[name] == null) {
|
||||||
defineReadOnly(this, name, run);
|
defineReadOnly(this, name, run);
|
||||||
} else {
|
} else {
|
||||||
console.log('WARNING: Multiple definitions for ' + name);
|
errors.warn('WARNING: Multiple definitions for ' + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.functions[name] == null) {
|
if (this.functions[name] == null) {
|
||||||
|
|
|
@ -141,3 +141,28 @@ export function checkNormalize(): void {
|
||||||
throwError('platform missing String.prototype.normalize', UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize', form: error.message });
|
throwError('platform missing String.prototype.normalize', UNSUPPORTED_OPERATION, { operation: 'String.prototype.normalize', form: error.message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const LogLevels: { [ name: string ]: number } = { debug: 1, "default": 2, info: 2, warn: 3, error: 4, off: 5 };
|
||||||
|
let LogLevel = LogLevels["default"];
|
||||||
|
|
||||||
|
export function setLogLevel(logLevel: string): void {
|
||||||
|
let level = LogLevels[logLevel];
|
||||||
|
if (level == null) {
|
||||||
|
warn("invliad log level - " + logLevel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LogLevel = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
function log(logLevel: string, args: Array<any>): void {
|
||||||
|
if (LogLevel > LogLevels[logLevel]) { return; }
|
||||||
|
console.log.apply(console, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function warn(...args: Array<any>): void {
|
||||||
|
log("warn", args);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function info(...args: Array<any>): void {
|
||||||
|
log("info", args);
|
||||||
|
}
|
||||||
|
|
|
@ -1224,7 +1224,7 @@ export class BaseProvider extends Provider {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _startPending(): void {
|
protected _startPending(): void {
|
||||||
console.log('WARNING: this provider does not support pending events');
|
errors.warn('WARNING: this provider does not support pending events');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _stopPending(): void {
|
protected _stopPending(): void {
|
||||||
|
|
|
@ -41,7 +41,7 @@ export class InfuraProvider extends JsonRpcProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _startPending(): void {
|
protected _startPending(): void {
|
||||||
console.log('WARNING: INFURA does not support pending filters');
|
errors.warn('WARNING: INFURA does not support pending filters');
|
||||||
}
|
}
|
||||||
|
|
||||||
getSigner(address?: string): JsonRpcSigner {
|
getSigner(address?: string): JsonRpcSigner {
|
||||||
|
|
|
@ -266,7 +266,7 @@ function parseSignatureEvent(fragment: string): EventFragment {
|
||||||
case '':
|
case '':
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.log('unknown modifier: ' + modifier);
|
errors.info('unknown modifier: ' + modifier);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ function parseSignatureFunction(fragment: string): FunctionFragment {
|
||||||
case '':
|
case '':
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.log('unknown modifier: ' + modifier);
|
errors.info('unknown modifier: ' + modifier);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -325,9 +325,13 @@ function addMethod(method: any): void {
|
||||||
sighash: sighash,
|
sighash: sighash,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Expose the first (and hopefully unique named function
|
// Expose the first (and hopefully unique named function)
|
||||||
if (method.name && this.functions[method.name] == null) {
|
if (method.name) {
|
||||||
defineReadOnly(this.functions, method.name, description);
|
if (this.functions[method.name] == null) {
|
||||||
|
defineReadOnly(this.functions, method.name, description);
|
||||||
|
} else {
|
||||||
|
errors.warn('WARNING: Multiple definitions for ' + method.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expose all methods by their signature, for overloaded functions
|
// Expose all methods by their signature, for overloaded functions
|
||||||
|
@ -368,7 +372,7 @@ function addMethod(method: any): void {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log('WARNING: unsupported ABI type - ' + method.type);
|
errors.warn('WARNING: unsupported ABI type - ' + method.type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ export function parse(rawTransaction: Arrayish): Transaction {
|
||||||
tx.v = bigNumberify(transaction[6]).toNumber();
|
tx.v = bigNumberify(transaction[6]).toNumber();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
errors.info(error);
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ export function parse(rawTransaction: Arrayish): Transaction {
|
||||||
try {
|
try {
|
||||||
tx.from = recoverAddress(digest, { r: hexlify(tx.r), s: hexlify(tx.s), recoveryParam: recoveryParam });
|
tx.from = recoverAddress(digest, { r: hexlify(tx.r), s: hexlify(tx.s), recoveryParam: recoveryParam });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
errors.info(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.hash = keccak256(rawTransaction);
|
tx.hash = keccak256(rawTransaction);
|
||||||
|
|
Loading…
Reference in New Issue