refactor: move to tslog

This commit is contained in:
ppedziwiatr
2021-08-24 15:04:37 +02:00
parent f923a46605
commit 3a9a121c2b
15 changed files with 36 additions and 31 deletions

View File

@@ -24,7 +24,7 @@ async function main() {
});
const swcClient = SwClientFactory.memCacheClient(arweave);
LoggerFactory.INST.logLevel('debug');
LoggerFactory.INST.logLevel('trace');
const contractTxId = 'W_njBtwDRyltjVU1RizJtZfF0S_4X3aSrrrA0HUEhUs';
const contractTxId2 = 'TMkCZKYO3GwcTLEKGgWSJegIlYCHi_UArtG0unCi2xA';

View File

@@ -215,7 +215,7 @@ async function main() {
logger.info('skipping ', contractTxId);
errorContractTxIds.push(contractTxId);
} finally {
logger.debug('Contracts with different states: %o', differentStatesContractTxIds);
logger.debug('Contracts with different states:', differentStatesContractTxIds);
logger.info('\n\n ==== END');
}
}
@@ -268,7 +268,7 @@ async function getNextPage(arweave, variables) {
variables
});
logger.verbose('Status:', response.status);
logger.debug('Status:', response.status);
if (response.status !== 200) {
throw new Error('Wrong response from Ar GQL');
}

View File

@@ -113,7 +113,7 @@ async function main() {
const sortedContracts = {};
sortable.forEach((item) => (sortedContracts[item[0]] = item[1]));
logger.debug('%o', sortedContracts);
logger.debug(sortedContracts);
fs.writeFileSync(path.join(__dirname, `swc-sorted-stats.json`), JSON.stringify(sortedContracts));
}

View File

@@ -49,6 +49,7 @@
"bignumber.js": "^9.0.1",
"bson": "^4.5.0",
"json-beautify": "^1.1.1",
"tslog": "^3.2.1",
"winston": "^3.3.3"
},
"devDependencies": {

View File

@@ -91,7 +91,7 @@ export class BsonFileBlockHeightSwCache<V = any> implements BlockHeightSwCache<V
// TODO: switch to async, as currently writing cache files may slow down contract execution.
try {
logger.verbose(`==== Storing cache update [${Object.keys(this.updatedStorage).length}] ====`);
logger.debug(`==== Storing cache update [${Object.keys(this.updatedStorage).length}] ====`);
const directoryPath = this.basePath;
Object.keys(this.updatedStorage).forEach((key) => {
const directory = key;

View File

@@ -42,7 +42,7 @@ export class HandlerBasedSwcClient implements SwcClient {
currentTx?: { interactionTxId: string; contractTxId: string }[],
evaluationOptions?: EvaluationOptions
): Promise<EvalStateResult<State>> {
logger.info('Read state for %s', contractTxId);
logger.info(`Read state for ${contractTxId}`);
logger.profile('Creating execution context');
const executionContext = await this.createExecutionContext(contractTxId, blockHeight, evaluationOptions);
logger.profile('Creating execution context');
@@ -62,7 +62,7 @@ export class HandlerBasedSwcClient implements SwcClient {
blockHeight?: number,
evaluationOptions?: EvaluationOptions
): Promise<InteractionResult<any, View>> {
logger.info('View state for %s', contractTxId);
logger.info(`View state for ${contractTxId}`);
logger.profile('Creating execution context');
let executionContext = await this.createExecutionContext(contractTxId, blockHeight, evaluationOptions);
logger.profile('Creating execution context');
@@ -121,7 +121,7 @@ export class HandlerBasedSwcClient implements SwcClient {
transaction: InteractionTx,
evaluationOptions?: EvaluationOptions
): Promise<InteractionResult<any, View>> {
logger.info('Vies state for %s %o', contractTxId, transaction);
logger.info(`Vies state for ${contractTxId}`, transaction);
logger.profile('Creating execution context');
const executionContext = await this.createExecutionContextFromTx(contractTxId, transaction);
logger.profile('Creating execution context');

View File

@@ -13,7 +13,7 @@ export class ContractDefinitionLoader<State = any> implements DefinitionLoader<S
async load(contractTxId: string, forcedSrcTxId?: string): Promise<ContractDefinition<State>> {
if (!forcedSrcTxId && this.cache?.contains(contractTxId)) {
logger.verbose('ContractDefinitionLoader: Hit from cache!');
logger.debug('ContractDefinitionLoader: Hit from cache!');
return Promise.resolve(this.cache?.get(contractTxId));
}

View File

@@ -94,7 +94,7 @@ export class ContractInteractionsLoader implements InteractionsLoader {
txInfos.push(...transactions.edges.filter((tx) => !tx.node.parent || !tx.node.parent.id));
}
logger.verbose('All interactions: %s', txInfos.length);
logger.debug('All interactions:', txInfos.length);
return txInfos;
}

View File

@@ -47,14 +47,11 @@ export class DefaultStateEvaluator<State = unknown> implements StateEvaluator<St
const validity = JSON.parse(JSON.stringify(baseState.validity));
logger.info(
'Evaluating state for %s [%s non-cached of %s all]',
executionContext.contractDefinition.txId,
missingInteractions.length,
executionContext.sortedInteractions.length
`Evaluating state for ${executionContext.contractDefinition.txId} [${missingInteractions.length} non-cached of ${executionContext.sortedInteractions.length} all]`
);
for (const missingInteraction of missingInteractions) {
logger.verbose(
logger.debug(
`${missingInteraction.node.id}: ${missingInteractions.indexOf(missingInteraction) + 1}/${
missingInteractions.length
} [of all:${executionContext.sortedInteractions.length}]`

View File

@@ -56,7 +56,7 @@ export class HandlerExecutorFactory<State = any> implements ExecutorFactory<Stat
try {
const stateCopy = JSON.parse(JSON.stringify(state));
swGlobal._activeTx = interactionTx;
logger.debug('SmartWeave.contract.id: %s', swGlobal.contract.id);
logger.debug(`SmartWeave.contract.id: ${swGlobal.contract.id}`, swGlobal.contract.id);
self.assignReadContractState(swGlobal, contractDefinition, interaction, executionContext, currentTx);
self.assignViewContractState(swGlobal, contractDefinition, executionContext);
@@ -99,7 +99,7 @@ export class HandlerExecutorFactory<State = any> implements ExecutorFactory<Stat
executionContext: ExecutionContext<State, HandlerApi<State>>
) {
swGlobal.contracts.viewContractState = async <View>(contractTxId: string, input: any) => {
logger.verbose('swGlobal.viewContractState call: %o', {
logger.debug('swGlobal.viewContractState call:', {
from: contractDefinition.txId,
to: contractTxId,
input
@@ -116,7 +116,7 @@ export class HandlerExecutorFactory<State = any> implements ExecutorFactory<Stat
currentTx: { interactionTxId: string; contractTxId: string }[]
) {
swGlobal.contracts.readContractState = async (contractTxId: string, height?: number, returnValidity?: boolean) => {
logger.verbose('swGlobal.readContractState call: ', {
logger.debug('swGlobal.readContractState call: ', {
from: contractDefinition.txId,
to: contractTxId,
interaction

View File

@@ -16,7 +16,7 @@ export class CacheableContractInteractionsLoader implements InteractionsLoader {
) {}
async load(contractId: string, blockHeight: number): Promise<GQLEdgeInterface[]> {
logger.debug('Loading interactions %o', {
logger.debug('Loading interactions', {
contractId,
blockHeight
});
@@ -24,7 +24,7 @@ export class CacheableContractInteractionsLoader implements InteractionsLoader {
const cached = this.cache.get(contractId, blockHeight);
if (cached !== null) {
logger.verbose('InteractionsLoader - hit from cache!');
logger.debug('InteractionsLoader - hit from cache!');
return cached.cachedValue;
} else {
const result = await this.baseImplementation.load(contractId, blockHeight);

View File

@@ -23,7 +23,7 @@ export class CacheableExecutorFactory<State, Api> implements ExecutorFactory<Sta
// with the same source).
const cacheKey = contractDefinition.txId;
if (!this.cache.contains(cacheKey)) {
logger.verbose('Updating executor factory cache');
logger.debug('Updating executor factory cache');
const handler = await this.baseImplementation.create(contractDefinition);
this.cache.put(cacheKey, handler);
}

View File

@@ -29,7 +29,7 @@ export class CacheableStateEvaluator<State> extends DefaultStateEvaluator<State>
currentTx: { interactionTxId: string; contractTxId: string }[]
): Promise<EvalStateResult<State>> {
const requestedBlockHeight = executionContext.blockHeight;
logger.verbose(`Requested state block height: ${requestedBlockHeight}`);
logger.debug(`Requested state block height: ${requestedBlockHeight}`);
let cachedState: BlockHeightCacheResult<EvalStateResult<State>> | null = null;
@@ -45,7 +45,7 @@ export class CacheableStateEvaluator<State> extends DefaultStateEvaluator<State>
cachedState = this.cache.getLessOrEqual(executionContext.contractDefinition.txId, requestedBlockHeight);
if (cachedState != null) {
logger.verbose(`Cached state for ${executionContext.contractDefinition.txId} %o`, {
logger.debug(`Cached state for ${executionContext.contractDefinition.txId}`, {
block: cachedState.cachedHeight,
requestedBlockHeight
});
@@ -57,7 +57,7 @@ export class CacheableStateEvaluator<State> extends DefaultStateEvaluator<State>
);
}
logger.verbose(`Interactions until [${requestedBlockHeight}] %o`, {
logger.debug(`Interactions until [${requestedBlockHeight}]`, {
total: sortedInteractionsUpToBlock.length,
cached: sortedInteractionsUpToBlock.length - missingInteractions.length
});
@@ -72,7 +72,7 @@ export class CacheableStateEvaluator<State> extends DefaultStateEvaluator<State>
if (entry.contractTxId === executionContext.contractDefinition.txId) {
const index = missingInteractions.findIndex((tx) => tx.node.id === entry.interactionTxId);
if (index !== -1) {
logger.verbose('Inf. Loop fix - removing interaction %o', {
logger.debug('Inf. Loop fix - removing interaction', {
contractTxId: entry.contractTxId,
interactionTxId: entry.interactionTxId
});
@@ -83,7 +83,7 @@ export class CacheableStateEvaluator<State> extends DefaultStateEvaluator<State>
// if cache is up-to date - return immediately to speed-up the whole process
if (missingInteractions.length === 0 && cachedState) {
logger.verbose(`State up to requested height [${requestedBlockHeight}] fully cached!`);
logger.debug(`State up to requested height [${requestedBlockHeight}] fully cached!`);
return cachedState.cachedValue;
}
}

View File

@@ -44,7 +44,7 @@ export class Evolve<State extends EvolveCompatibleState, Api> implements Executi
async modify(state: State, executionContext: ExecutionContext<State, Api>): Promise<ExecutionContext<State, Api>> {
const contractTxId = executionContext.contractDefinition.txId;
logger.verbose(`trying to evolve for: ${contractTxId}`);
logger.debug(`trying to evolve for: ${contractTxId}`);
const currentSrcTxId = executionContext.contractDefinition.srcTxId;
const settings =
@@ -60,7 +60,7 @@ export class Evolve<State extends EvolveCompatibleState, Api> implements Executi
canEvolve = true;
}
if (evolve && /[a-z0-9_-]{43}/i.test(evolve) && canEvolve) {
logger.debug('Checking evolve: %o', {
logger.debug('Checking evolve:', {
current: currentSrcTxId,
evolve
});
@@ -68,7 +68,7 @@ export class Evolve<State extends EvolveCompatibleState, Api> implements Executi
if (currentSrcTxId !== evolve) {
try {
// note: that's really nasty IMO - loading original contract definition, but forcing different sourceTxId...
logger.info('Evolving to: %s', evolve);
logger.info(`Evolving to: ${evolve}`);
const newContractDefinition = await this.definitionLoader.load(contractTxId, evolve);
const newHandler = await this.executorFactory.create(newContractDefinition);
@@ -77,7 +77,7 @@ export class Evolve<State extends EvolveCompatibleState, Api> implements Executi
contractDefinition: newContractDefinition,
handler: newHandler
};
logger.verbose('evolved to: %o', {
logger.debug('evolved to:', {
txId: modifiedContext.contractDefinition.txId,
srcTxId: modifiedContext.contractDefinition.srcTxId
});

View File

@@ -5252,7 +5252,7 @@ smartweave@^0.4.41:
sentencer "^0.2.1"
yargs "^16.2.0"
source-map-support@^0.5.6:
source-map-support@^0.5.19, source-map-support@^0.5.6:
version "0.5.19"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
@@ -5748,6 +5748,13 @@ tslib@^2.1.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==
tslog@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/tslog/-/tslog-3.2.1.tgz#37df1301211901eb65fd61b9ad7c8554264a7699"
integrity sha512-m8wAtox9wt+h6UDcN1WAQnYwRDOGhMIOp+GAuuufo8T8qKuu726i2W3r47BrA69goVOwgUkp5YwDTvAxTktvPg==
dependencies:
source-map-support "^0.5.19"
tsscmp@1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/tsscmp/-/tsscmp-1.0.6.tgz#85b99583ac3589ec4bfef825b5000aa911d605eb"