Skip to content

Commit 6428a16

Browse files
committed
get logger separated to another file
1 parent 9746e3d commit 6428a16

File tree

10 files changed

+22
-34
lines changed

10 files changed

+22
-34
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.

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

src/packages/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as bitcoin from "bitcoinjs-lib";
2-
// import fetch, { RequestInit } from "node-fetch";
32
import request from "request";
4-
import { cacheStorage, getLogger } from "../index";
3+
import { cacheStorage} from "../index";
54
import { ErrorHelper, PackageErrorCode } from "./error";
5+
import { getLogger } from "./logger";
66
import { IBitcoinKeyPair } from "./name-service/blockstack-service";
77

88
const log = getLogger(__filename);

0 commit comments

Comments
 (0)