Skip to content

Commit

Permalink
fix: opt log (#57)
Browse files Browse the repository at this point in the history
* fix: opt log

* feat(log): 增加file类型的日志输出

* chore(log): opt ckb & eth handler log

* chore(log): opt ci test log

* fix: update tron-ci test order, to fix tron ci test failed cause by local time large then tron test server time

Co-authored-by: wangbing <wangbing@cryptape.com>
  • Loading branch information
solargatsby and wangbing committed May 11, 2021
1 parent f2e8022 commit 00cbbcf
Show file tree
Hide file tree
Showing 22 changed files with 447 additions and 285 deletions.
5 changes: 5 additions & 0 deletions offchain-modules/config-cli.json.example
@@ -1,5 +1,10 @@
{
"forceBridge": {
"common": {
"log": {
"level": "info"
}
},
"eth": {
"rpcUrl": "http://47.56.233.149:3045",
"privateKey": "0xc4ad657963930fbff2e9de3404b30a4e21432c89952ed430b56bf802945ed37a",
Expand Down
5 changes: 5 additions & 0 deletions offchain-modules/config.json.example
@@ -1,5 +1,10 @@
{
"forceBridge": {
"common": {
"log": {
"level": "info"
}
},
"eth": {
"rpcUrl": "http://127.0.0.1:8545",
"privateKey": "0xc4ad657963930fbff2e9de3404b30a4e21432c89952ed430b56bf802945ed37a",
Expand Down
2 changes: 1 addition & 1 deletion offchain-modules/ormconfig.js
Expand Up @@ -9,7 +9,7 @@ module.exports = {
database: 'forcebridge',
timezone: 'Z',
synchronize: true,
logging: true,
logging: false,
entities: ['{.,dist}/src/packages/db/entity/*.{ts,js}'],
namingStrategy: new SnakeNamingStrategy(),
};
108 changes: 77 additions & 31 deletions offchain-modules/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions offchain-modules/package.json
Expand Up @@ -25,7 +25,7 @@
"tron-test": "ts-node ./src/scripts/integration-test/tron.ts",
"prepare-xchain-test": "sleep 2",
"btc-test": "ts-node ./src/scripts/integration-test/btc.ts",
"xchain-test": "run-s prepare-xchain-test eth-test tron-test btc-test eos-test",
"xchain-test": "run-s prepare-xchain-test eth-test btc-test eos-test tron-test",
"integration-test": "run-p -r start xchain-test",
"ci": "run-s clean build deploy integration-test",
"test:unit": "nyc --silent ava",
Expand Down Expand Up @@ -93,7 +93,7 @@
"sqlite3": "^5.0.2",
"trongrid": "^1.2.6",
"tronweb": "^3.2.3",
"typeorm": "^0.2.31",
"typeorm": "^0.2.32",
"typeorm-naming-strategies": "^2.0.0"
},
"ava": {
Expand Down
7 changes: 7 additions & 0 deletions offchain-modules/src/apps/cli/utils.ts
Expand Up @@ -5,12 +5,19 @@ import { Asset } from '../../packages/ckb/model/asset';
import { IndexerCollector } from '../../packages/ckb/tx-helper/collector';
import { Amount, Script } from '@lay2/pw-core';
import { asyncSleep } from '@force-bridge/utils';
import { initLog } from '@force-bridge/utils/logger';

const defaultLogFile = './log/force-bridge-cli.log';

export async function initConfig() {
const configPath = process.env.CONFIG_PATH || './config-cli.json';
nconf.env().file({ file: configPath });
const config: Config = nconf.get('forceBridge');
await new ForceBridgeCore().init(config);
if (!config.common.log.logFile) {
config.common.log.logFile = defaultLogFile;
}
initLog(ForceBridgeCore.config.common.log);
}

export function parseOptions(args: any, command: any): Map<string, string> {
Expand Down
9 changes: 9 additions & 0 deletions offchain-modules/src/apps/relayer/index.ts
Expand Up @@ -14,11 +14,20 @@ import { TronHandler } from '@force-bridge/handlers/tron';
import { BtcDb } from '@force-bridge/db/btc';
import { BTCChain } from '@force-bridge/xchain/btc';
import { BtcHandler } from '@force-bridge/handlers/btc';
import { initLog } from '@force-bridge/utils/logger';

const defaultLogFile = './log/force-bridge-relay.log';

async function main() {
const configPath = process.env.CONFIG_PATH || './config.json';
nconf.env().file({ file: configPath });
const config: Config = nconf.get('forceBridge');
if (!config.common.log.logFile) {
config.common.log.logFile = defaultLogFile;
}

// init log
initLog(config.common.log);
// init bridge force core
await new ForceBridgeCore().init(config);

Expand Down
7 changes: 6 additions & 1 deletion offchain-modules/src/apps/rpc/index.ts
Expand Up @@ -5,14 +5,15 @@ import 'module-alias/register';
import { JSONRPCServer } from 'json-rpc-2.0';
import { rpcConfig } from '@force-bridge/config';
import nconf from 'nconf';
import { logger } from '@force-bridge/utils/logger';
import { logger, initLog } from '@force-bridge/utils/logger';
import { ForceBridgeAPIV1Handler } from './handler';
import { ForceBridgeCore } from '@force-bridge/core';
import { Config } from '@force-bridge/config';
import { createConnection } from 'typeorm';
import { GetBalancePayload, GetBridgeTransactionSummariesPayload } from './types/apiv1';

const forceBridgePath = '/force-bridge/api/v1';
const defaultLogFile = './log/force-bridge-rpc.log';

async function main() {
const configPath = process.env.CONFIG_PATH || './config.json';
Expand All @@ -21,6 +22,10 @@ async function main() {
const config: Config = nconf.get('forceBridge');
const rpcConfig: rpcConfig = nconf.get('forceBridge:rpc');
await new ForceBridgeCore().init(config);
if (!config.common.log.logFile) {
config.common.log.logFile = defaultLogFile;
}
initLog(ForceBridgeCore.config.common.log);

const server = new JSONRPCServer();

Expand Down
10 changes: 10 additions & 0 deletions offchain-modules/src/packages/config.ts
Expand Up @@ -83,7 +83,17 @@ export interface rpcConfig {
};
}

export interface logConfig {
level: string;
logFile: string;
}

export interface commonConfig {
log: logConfig;
}

export interface Config {
common: commonConfig;
ckb: CkbConfig;
eth?: EthConfig;
eos?: EosConfig;
Expand Down

0 comments on commit 00cbbcf

Please sign in to comment.