Skip to content

Commit 339d6f3

Browse files
authored
Merge pull request #99 from cruxprotocol/feature/logger-separated
Shift logger to subpackage
2 parents f31c508 + 6428a16 commit 339d6f3

File tree

11 files changed

+22
-36
lines changed

11 files changed

+22
-36
lines changed

package-lock.json

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"@types/chai": "^4.2.3",
6161
"@types/expect": "^1.20.4",
6262
"@types/mocha": "^5.2.7",
63-
"@types/node-fetch": "^2.5.2",
6463
"@types/request": "^2.48.3",
6564
"@types/sinon": "^7.0.13",
6665
"chai": "^4.2.0",
@@ -90,7 +89,6 @@
9089
"blockstack": "^19.2.5",
9190
"js-logger": "^1.6.0",
9291
"jsontokens": "^2.0.2",
93-
"node-fetch": "^2.6.0",
9492
"regenerator-runtime": "^0.13.3"
9593
}
9694
}

src/index.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
import Logger from "js-logger";
2-
import path from "path";
31
import "regenerator-runtime/runtime";
42
import config from "./config";
5-
6-
// Setup logging configuration
7-
Logger.useDefaults();
8-
Logger.setLevel(config.CONFIG_MODE === "prod" ? Logger.INFO : Logger.DEBUG);
9-
export function getLogger(filename: string) {
10-
return Logger.get("CruxPay: " + filename.slice(filename.lastIndexOf(path.sep) + 1, filename.length - 3));
11-
}
12-
const log = getLogger(__filename);
13-
143
// Importing packages
154
import {
165
blockstackService,
@@ -22,8 +11,11 @@ import {
2211
storage,
2312
utils,
2413
} from "./packages";
14+
import { getLogger } from "./packages/logger";
2515
import { getCruxIDByAddress } from "./packages/name-service/utils";
2616

17+
const log = getLogger(__filename);
18+
2719
// Setup cache storage
2820
export let cacheStorage: storage.StorageService;
2921

src/packages/configuration-service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { getLogger } from "..";
21
import config from "../config";
32
import { ErrorHelper, PackageErrorCode } from "./error";
43
import { getContentFromGaiaHub, getGaiaDataFromBlockstackID } from "./gaia-service/utils";
54
import * as identityUtils from "./identity-utils";
5+
import { getLogger } from "./logger";
66
import { IIdentityClaim } from "./name-service";
77
import * as blockstackService from "./name-service/blockstack-service";
8-
import { getCruxIDByAddress } from "./name-service/utils";
98

109
const log = getLogger(__filename);
1110
const CONFIG_SUBDOMAIN = "_config";

src/packages/gaia-service/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as blockstack from "blockstack";
22
import { SECP256K1Client, TokenSigner } from "jsontokens";
3-
import { getLogger } from "../..";
3+
import { getLogger } from "../logger";
44
import { sanitizePrivKey } from "../utils";
55

66
const log = getLogger(__filename);

src/packages/gaia-service/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as blockstack from "blockstack";
2-
import { getLogger } from "../..";
32
import { ErrorHelper, PackageErrorCode } from "../error";
3+
import { getLogger } from "../logger";
44
import * as nameservice from "../name-service/blockstack-service";
55
import { fetchNameDetails } from "../name-service/utils";
66
import { cachedFunctionCall, httpJSONRequest } from "../utils";

src/packages/logger.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Logger from "js-logger";
2+
import path from "path";
3+
import config from "../config";
4+
5+
// Setup logging configuration
6+
Logger.useDefaults();
7+
Logger.setLevel(config.CONFIG_MODE === "prod" ? Logger.INFO : Logger.DEBUG);
8+
export function getLogger(filename: string) {
9+
return Logger.get("CruxPay: " + filename.slice(filename.lastIndexOf(path.sep) + 1, filename.length - 3));
10+
}

src/packages/name-service/blockstack-service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Decoder, object, optional, string } from "@mojotech/json-type-validatio
22
import * as bip39 from "bip39";
33
import {bip32} from "bitcoinjs-lib";
44
import * as blockstack from "blockstack";
5-
import { getLogger, IAddress, IAddressMapping } from "../..";
5+
import { IAddress, IAddressMapping } from "../..";
66

77
import {randomBytes} from "crypto";
88
import { Encryption } from "../encryption";
@@ -11,6 +11,7 @@ import { PackageError } from "../error/package-error";
1111
import { GaiaService } from "../gaia-service";
1212
import { getContentFromGaiaHub } from "../gaia-service/utils";
1313
import { BlockstackId, CRUX_DOMAIN_SUFFIX, CruxId, DEFAULT_BLOCKSTACK_NAMESPACE, IdTranslator } from "../identity-utils";
14+
import { getLogger } from "../logger";
1415
import { StorageService } from "../storage";
1516
import * as utils from "../utils";
1617
import * as nameService from "./index";

src/packages/name-service/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AssertionError, deepStrictEqual } from "assert";
2-
import { getLogger } from "../..";
32
import { ErrorHelper, PackageErrorCode } from "../error";
43
import { BlockstackId, CRUX_DOMAIN_SUFFIX, DEFAULT_BLOCKSTACK_NAMESPACE, IdTranslator } from "../identity-utils";
4+
import { getLogger } from "../logger";
55
import { cachedFunctionCall, httpJSONRequest } from "../utils";
66

77
const log = getLogger(__filename);

src/packages/storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getLogger } from "..";
1+
import { getLogger } from "./logger";
22

33
const log = getLogger(__filename);
44

0 commit comments

Comments
 (0)