Allow logging with colors (based on type) (#133)
This commit is contained in:
+1
-1
@@ -11,6 +11,6 @@
|
||||
"test": "jest --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/dev": "^0.19.12"
|
||||
"@polkadot/dev": "^0.19.18"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,5 @@ module.exports = function pairs (storage: Temp$Storage): Trie$Pairs {
|
||||
// flowlint-next-line unclear-type:off
|
||||
const keys = ((Object.keys(storage): any): Array<Uint8Array>);
|
||||
|
||||
return keys
|
||||
// $FlowFixMe we are filtering out the nulls next, don't panic
|
||||
.map((k) => storage[k])
|
||||
.filter((v) => v !== null);
|
||||
return keys.map((k) => storage[k]);
|
||||
};
|
||||
|
||||
@@ -5,11 +5,6 @@
|
||||
|
||||
import type { Trie$Pair } from '@polkadot/util-triehash/types';
|
||||
|
||||
type Trie$PairNull = {
|
||||
k: Uint8Array,
|
||||
v: null
|
||||
};
|
||||
|
||||
export type Temp$Storage = {
|
||||
[Uint8Array]: Trie$Pair | Trie$PairNull
|
||||
[Uint8Array]: Trie$Pair
|
||||
};
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.0.0-beta.47",
|
||||
"bn.js": "^4.11.8",
|
||||
"chalk": "^2.4.1",
|
||||
"deasync": "^0.1.12",
|
||||
"ip-regex": "^2.1.0"
|
||||
}
|
||||
|
||||
@@ -6,16 +6,40 @@
|
||||
import type { Logger, Logger$Data } from './types';
|
||||
|
||||
type ConsoleType = 'error' | 'log' | 'warn';
|
||||
type LogType = ConsoleType | 'debug';
|
||||
|
||||
const chalk = require('chalk');
|
||||
|
||||
const isFunction = require('./is/function');
|
||||
|
||||
function apply (log: ConsoleType, type: string, values: Logger$Data): void {
|
||||
const logTo: { [LogType]: ConsoleType } = {
|
||||
debug: 'log',
|
||||
error: 'error',
|
||||
log: 'log',
|
||||
warn: 'warn'
|
||||
};
|
||||
|
||||
const chalked: { [LogType]: (value: string) => string } = {
|
||||
debug: chalk.gray,
|
||||
error: chalk.red,
|
||||
log: chalk.reset,
|
||||
warn: chalk.yellow
|
||||
};
|
||||
|
||||
function apply (log: LogType, type: string, values: Logger$Data): void {
|
||||
if (values.length === 1 && isFunction(values[0])) {
|
||||
// flowlint-next-line unclear-type:off
|
||||
return apply(log, type, ((values[0]: any): Function)());
|
||||
}
|
||||
|
||||
console[log].apply(console, [new Date().toString(), type].concat(values));
|
||||
const chalk = (value: string): string =>
|
||||
chalked[log](value);
|
||||
|
||||
console[logTo[log]].apply(
|
||||
console, [
|
||||
chalk(new Date().toString()), chalk(type)
|
||||
].concat(values)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,7 +68,7 @@ module.exports = function logger (_type: string): Logger {
|
||||
|
||||
return {
|
||||
debug: isDebug
|
||||
? (...values: Logger$Data): void => apply('log', type, values)
|
||||
? (...values: Logger$Data): void => apply('debug', type, values)
|
||||
: (...values: Logger$Data): void => void 0,
|
||||
error: (...values: Logger$Data): void => apply('error', type, values),
|
||||
log: (...values: Logger$Data): void => apply('log', type, values),
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('logger', () => {
|
||||
expect(spy.log).toHaveBeenCalledWith(
|
||||
dateMatch,
|
||||
prefixMatch,
|
||||
'console.log test'
|
||||
expect.stringMatching('console.log test')
|
||||
);
|
||||
});
|
||||
|
||||
@@ -54,8 +54,8 @@ describe('logger', () => {
|
||||
expect(spy.log).toHaveBeenCalledWith(
|
||||
dateMatch,
|
||||
prefixMatch,
|
||||
'test',
|
||||
'a',
|
||||
expect.stringMatching('test'),
|
||||
expect.stringMatching('a'),
|
||||
2
|
||||
);
|
||||
});
|
||||
@@ -66,7 +66,7 @@ describe('logger', () => {
|
||||
expect(spy.log).toHaveBeenCalledWith(
|
||||
dateMatch,
|
||||
prefixMatch,
|
||||
'a function test'
|
||||
expect.stringMatching('a function test')
|
||||
);
|
||||
});
|
||||
|
||||
@@ -76,7 +76,7 @@ describe('logger', () => {
|
||||
expect(spy.error).toHaveBeenCalledWith(
|
||||
dateMatch,
|
||||
prefixMatch,
|
||||
'console.error test'
|
||||
expect.stringMatching('console.error test')
|
||||
);
|
||||
});
|
||||
|
||||
@@ -86,7 +86,7 @@ describe('logger', () => {
|
||||
expect(spy.warn).toHaveBeenCalledWith(
|
||||
dateMatch,
|
||||
prefixMatch,
|
||||
'console.warn test'
|
||||
expect.stringMatching('console.warn test')
|
||||
);
|
||||
});
|
||||
|
||||
@@ -96,7 +96,7 @@ describe('logger', () => {
|
||||
expect(spy.log).toHaveBeenCalledWith(
|
||||
dateMatch,
|
||||
prefixMatch,
|
||||
'test'
|
||||
expect.stringMatching('test')
|
||||
);
|
||||
});
|
||||
|
||||
@@ -107,7 +107,7 @@ describe('logger', () => {
|
||||
expect(spy.log).toHaveBeenCalledWith(
|
||||
dateMatch,
|
||||
expect.stringMatching(/TESTING:/),
|
||||
'test'
|
||||
expect.stringMatching('test')
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -664,9 +664,9 @@
|
||||
lodash "^4.17.5"
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@polkadot/dev@^0.19.12":
|
||||
version "0.19.12"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.19.12.tgz#9d2e45628f47adffeb0ebc1727d2ab6c9f717cd7"
|
||||
"@polkadot/dev@^0.19.18":
|
||||
version "0.19.18"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.19.18.tgz#f03861c66ce246851b1f96a6b5f0167747b6d3f4"
|
||||
dependencies:
|
||||
"@babel/cli" "^7.0.0-beta.47"
|
||||
"@babel/core" "^7.0.0-beta.47"
|
||||
@@ -692,7 +692,7 @@
|
||||
eslint-plugin-node "^6.0.1"
|
||||
eslint-plugin-promise "^3.7.0"
|
||||
eslint-plugin-standard "^3.0.1"
|
||||
flow-bin "^0.72.0"
|
||||
flow-bin "^0.73.0"
|
||||
flow-copy-source "^1.3.0"
|
||||
jest "^22.4.3"
|
||||
lerna "^2.11.0"
|
||||
@@ -807,6 +807,12 @@ ansi-styles@^3.1.0, ansi-styles@^3.2.0:
|
||||
dependencies:
|
||||
color-convert "^1.9.0"
|
||||
|
||||
ansi-styles@^3.2.1:
|
||||
version "3.2.1"
|
||||
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
|
||||
dependencies:
|
||||
color-convert "^1.9.0"
|
||||
|
||||
anymatch@^1.3.0:
|
||||
version "1.3.2"
|
||||
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.2.tgz#553dcb8f91e3c889845dfdba34c77721b90b9d7a"
|
||||
@@ -1378,6 +1384,14 @@ chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0:
|
||||
escape-string-regexp "^1.0.5"
|
||||
supports-color "^4.0.0"
|
||||
|
||||
chalk@^2.4.1:
|
||||
version "2.4.1"
|
||||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e"
|
||||
dependencies:
|
||||
ansi-styles "^3.2.1"
|
||||
escape-string-regexp "^1.0.5"
|
||||
supports-color "^5.3.0"
|
||||
|
||||
chardet@^0.4.0:
|
||||
version "0.4.2"
|
||||
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"
|
||||
@@ -2438,9 +2452,9 @@ flat-cache@^1.2.1:
|
||||
graceful-fs "^4.1.2"
|
||||
write "^0.2.1"
|
||||
|
||||
flow-bin@^0.72.0:
|
||||
version "0.72.0"
|
||||
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.72.0.tgz#12051180fb2db7ccb728fefe67c77e955e92a44d"
|
||||
flow-bin@^0.73.0:
|
||||
version "0.73.0"
|
||||
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.73.0.tgz#da1b90a02b0ef9c439f068c2fc14968db83be425"
|
||||
|
||||
flow-copy-source@^1.3.0:
|
||||
version "1.3.0"
|
||||
@@ -2815,6 +2829,10 @@ has-flag@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-2.0.0.tgz#e8207af1cc7b30d446cc70b734b5e8be18f88d51"
|
||||
|
||||
has-flag@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
|
||||
|
||||
has-unicode@^2.0.0:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9"
|
||||
@@ -5521,6 +5539,12 @@ supports-color@^4.0.0:
|
||||
dependencies:
|
||||
has-flag "^2.0.0"
|
||||
|
||||
supports-color@^5.3.0:
|
||||
version "5.4.0"
|
||||
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54"
|
||||
dependencies:
|
||||
has-flag "^3.0.0"
|
||||
|
||||
symbol-observable@1.0.4:
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.4.tgz#29bf615d4aa7121bdd898b22d4b3f9bc4e2aa03d"
|
||||
|
||||
Reference in New Issue
Block a user