Skip to content

Commit 143d2b4

Browse files
committed
feat(logger): update log statements
1 parent 438e3ae commit 143d2b4

17 files changed

+51
-36
lines changed

embed/src/main.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import "dotenv/config";
22

33
// ---- Main App from index
44
import { app } from "./server.js";
5-
5+
import { logger } from "./utils/logger.js";
66
// default port to listen on
77
const port = process.env.EMBED_PORT || 80;
88

99
const startServer = (): void => {
1010
const server = app.listen(port, () => {
1111
// eslint-disable-next-line no-console
12-
console.log(`server started at http://localhost:${port}`);
12+
logger.info(`server started at http://localhost:${port}`);
1313
});
1414

1515
// This should be > the ELB idle timeout, which is 60 seconds
@@ -21,5 +21,5 @@ try {
2121
startServer();
2222
} catch (error) {
2323
// eslint-disable-next-line no-console
24-
console.error(error);
24+
logger.error(error);
2525
}

embed/src/redis.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Redis } from "ioredis";
2-
2+
import { logger } from "./utils/logger.js";
33
export const redis = new Redis(process.env.REDIS_URL as string);
44

55
// Log errors and connection success
66
redis.on("connect", () => {
7-
console.log("Connected to Redis");
7+
logger.info("Connected to Redis");
88
});
99

1010
redis.on("error", (err) => {
11-
console.error("Redis connection error:", err);
11+
logger.error("Redis connection error:", err);
1212
});

embed/src/server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { keyGenerator } from "./rateLimiterKeyGenerator.js";
1414
import { autoVerificationHandler, verificationHandler, getChallengeHandler } from "./handlers.js";
1515
import { metadataHandler } from "./metadata.js";
1616
import { serverUtils } from "./utils/identityHelper.js";
17-
17+
import { logger } from "./utils/logger.js";
1818
// ---- Config - check for all required env variables
1919
// We want to prevent the app from starting with default values or if it is misconfigured
2020
const configErrors = [];
@@ -41,7 +41,7 @@ if (!process.env.REDIS_URL) {
4141
}
4242

4343
if (configErrors.length > 0) {
44-
configErrors.forEach((error) => console.error(error)); // eslint-disable-line no-console
44+
configErrors.forEach((error) => logger.error(error));
4545
throw new Error("Missing required configuration: " + configErrors.join(",\n"));
4646
}
4747

embed/src/utils/logger.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pinoImport from "pino";
2+
const pino = pinoImport.default;
3+
// https://github.com/pinojs/pino
4+
5+
export const logger = pino();
6+
7+
logger.info("Logger initialized");

iam/src/index.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ import { challengeHandler, checkHandler, easScoreV2Handler, verifyHandler } from
1010
import { serverUtils } from "./utils/identityHelper.js";
1111
import { logger } from "./utils/logger.js";
1212

13-
logger.info("Hello initial log ");
14-
logger.info("Hello multi line log");
15-
logger.info(`This is a multi-line log message:
16-
Line 1: Application is starting.
17-
Line 2: Environment variables are being checked.
18-
Line 3: Initialization is in progress.`);
19-
2013
// ---- Config - check for all required env variables
2114
// We want to prevent the app from starting with default values or if it is misconfigured
2215
const configErrors = [
@@ -40,7 +33,7 @@ const configErrors = [
4033
.filter(Boolean);
4134

4235
if (configErrors.length > 0) {
43-
configErrors.forEach((error) => console.error(error)); // eslint-disable-line no-console
36+
configErrors.forEach((error) => logger.error(error));
4437
throw new Error("Missing required configuration");
4538
}
4639

iam/src/main.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import "dotenv/config";
2+
import { logger } from "./utils/logger.js";
23

34
// ---- Main App from index
45
import { app } from "./index.js";
@@ -13,15 +14,13 @@ const startServer = async (): Promise<void> => {
1314
});
1415

1516
const server = app.listen(port, () => {
16-
// eslint-disable-next-line no-console
17-
console.log(`server started at http://localhost:${port}`);
17+
logger.info(`server started at http://localhost:${port}`);
1818
});
1919

2020
// This should be > the ELB idle timeout, which is 60 seconds
2121
server.keepAliveTimeout = 61 * 1000;
2222
};
2323

2424
startServer().catch((error) => {
25-
// eslint-disable-next-line no-console
26-
console.error(error);
25+
logger.error(error);
2726
});

iam/src/utils/easFees.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { parseEther } from "ethers";
22
import Moralis from "moralis";
33
import { PassportCache } from "@gitcoin/passport-platforms";
4+
import { logger } from "./logger.js";
45

56
const FIVE_MINUTES = 1000 * 60 * 5;
67
const WETH_CONTRACT = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
@@ -43,12 +44,12 @@ class EthPriceLoader {
4344
} catch (e) {
4445
let message = "Failed to cache ETH price";
4546
if (e instanceof Error) message += `, ${e.name}: ${e.message}`;
46-
console.error(`REDIS CONNECTION ERROR: ${message}`);
47+
logger.error(`REDIS CONNECTION ERROR: ${message}`);
4748
}
4849
} catch (e) {
4950
let message = "Failed to get ETH price";
5051
if (e instanceof Error) message += `, ${e.name}: ${e.message}`;
51-
console.error(`MORALIS ERROR: ${message}`);
52+
logger.error(`MORALIS ERROR: ${message}`);
5253
}
5354
}
5455
}

iam/src/utils/revocations.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { handleAxiosError } from "@gitcoin/passport-platforms";
22
import axios from "axios";
33
import { VerifiableCredential, VerifiableEip712Credential } from "@gitcoin/passport-types";
44
import { serverUtils } from "../utils/identityHelper.js";
5-
5+
import { logger } from "./logger.js";
66
const { InternalApiError } = serverUtils;
77

88
const SCORER_ENDPOINT = process.env.SCORER_ENDPOINT;
@@ -48,7 +48,7 @@ export const filterRevokedCredentials = async (
4848
const fetchRevocations = async (proofValues: string[]): Promise<Revocation[]> => {
4949
const payload = { proof_values: proofValues };
5050

51-
console.log("Checking revocations", payload);
51+
logger.info("Checking revocations", payload);
5252

5353
try {
5454
const revocationResponse: {

identity/src/credentials.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from "./signingDocuments.js";
2020
import { IgnorableNullifierGeneratorError, NullifierGenerator } from "./nullifierGenerators.js";
2121
import { checkRotatingKeysEnabled } from "./helpers.js";
22+
import { logger } from "./logger.js";
2223

2324
// Control expiry times of issued credentials
2425
export const CHALLENGE_EXPIRES_AFTER_SECONDS = 60; // 1min
@@ -137,7 +138,7 @@ const getNullifiers = async ({
137138
.filter((result) => !(result.reason instanceof IgnorableNullifierGeneratorError));
138139

139140
if (unexpectedErrors.length > 0) {
140-
console.error("Unexpected errors generating nullifiers", unexpectedErrors); // eslint-disable-line no-console
141+
logger.error("Unexpected errors generating nullifiers", unexpectedErrors); // eslint-disable-line no-console
141142
throw new Error("Unable to generate nullifiers");
142143
}
143144

identity/src/humanNetworkOprf.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { readFileSync } from "fs";
22
import { join, dirname } from "path";
33

44
import { initSync as humanNetworkInitSync, generate_oprf, enable_errors } from "@holonym-foundation/mishtiwasm";
5+
import { logger } from "./logger.js";
56

67
// TODO: ideally this would be handled in the wasm module
78
process.on("uncaughtException", (err): void => {
8-
console.error("Uncaught exception:", err); // eslint-disable-line no-console
9+
logger.error("Uncaught exception:", err); // eslint-disable-line no-console
910
if (!err.toString().includes("RuntimeError: unreachable")) {
1011
throw err;
1112
}
@@ -26,7 +27,7 @@ const initializeHumanNetwork = () => {
2627
// TODO leaving in in case there are any weird
2728
// issues in other environments, but can be removed
2829
// next time we're in this file
29-
console.log("Loading wasm module", wasmPath);
30+
logger.info("Loading wasm module", wasmPath);
3031

3132
const wasmModuleBuffer = readFileSync(wasmPath);
3233

identity/src/keyManager.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// key in the list, with version "0.0.0"
2121

2222
import { checkRotatingKeysEnabled } from "./helpers.js";
23-
23+
import { logger } from "./logger.js";
2424
const MAX_CONCURRENT_KEYS = 2;
2525

2626
const LEGACY_KEY_ENV_NAME = "IAM_JWK_EIP712";
@@ -80,7 +80,7 @@ const getLegacyKeyVersion = (): KeyVersion | undefined => {
8080
const key = process.env[LEGACY_KEY_ENV_NAME];
8181

8282
if (!key) {
83-
console.warn(`Warning: No legacy key (${LEGACY_KEY_ENV_NAME}) found in ENV`);
83+
logger.warn(`Warning: No legacy key (${LEGACY_KEY_ENV_NAME}) found in ENV`);
8484
}
8585

8686
return (
@@ -109,7 +109,7 @@ const loadInitiatedRotatingKeyVersions = (): KeyVersion[] => {
109109
}
110110

111111
if (initiatedKeyVersions.length === 0) {
112-
console.warn("Warning: No valid IAM_JWK_EIP712_V* keys configured");
112+
logger.warn("Warning: No valid IAM_JWK_EIP712_V* keys configured");
113113
}
114114

115115
return initiatedKeyVersions;

identity/src/logger.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pinoImport from "pino";
2+
const pino = pinoImport.default;
3+
// https://github.com/pinojs/pino
4+
5+
export const logger = pino();
6+
7+
logger.info("Logger initialized");

identity/src/nullifierGenerators.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as base64 from "@ethersproject/base64";
88
import { createHash } from "crypto";
99
import { objToSortedArray } from "./helpers.js";
1010
import { humanNetworkOprf } from "./humanNetworkOprf.js";
11+
import { logger } from "./logger.js";
1112

1213
export type NullifierGenerator = ({ record }: { record: ProofRecord }) => Promise<string>;
1314

@@ -124,7 +125,7 @@ export const HumanNetworkNullifierGenerator =
124125
} catch (e) {
125126
// For now, ignore errors with humanNetwork
126127
// TODO remove this once beta testing is complete
127-
console.error("Error generating humanNetwork nullifier (ignoring): ", e);
128+
logger.error("Error generating humanNetwork nullifier (ignoring): ", e);
128129
throw new IgnorableNullifierGeneratorError("Error generating humanNetwork nullifier");
129130
}
130131
};

identity/src/serverUtils/errorHandlerMiddleware.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Request, Response } from "express";
22
import { ApiError } from "./apiError.js";
3-
3+
import { logger } from "./logger.js";
44
// Middleware to handle errors
55
// Must define 4 params for express to recognize this as an error handler
66
export const errorHandlerMiddleware = (err: Error, _req: Request, res: Response, _next: unknown) => {
@@ -19,7 +19,7 @@ export const errorHandlerMiddleware = (err: Error, _req: Request, res: Response,
1919
// user reaches out with issues
2020
const randomID = Math.random().toString(36).substring(2, 8);
2121

22-
console.log("Unexpected error:", formatSystemMessage(err, randomID)); // eslint-disable-line no-console
22+
logger.debug("Unexpected error:", formatSystemMessage(err, randomID));
2323

2424
return res.status(500).json(formatUserResponse(err, randomID));
2525
};

identity/src/verification.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { platforms, providers } from "@gitcoin/passport-platforms";
66
import { issueNullifiableCredential } from "./credentials.js";
77
import { checkCredentialBans } from "./bans.js";
88
import { getIssuerInfo } from "./issuers.js";
9+
import { logger } from "./logger.js";
910

1011
import * as DIDKit from "@spruceid/didkit-wasm-node";
1112

@@ -114,7 +115,7 @@ export async function verifyTypes(
114115
const resultErrors = verifyResult.errors;
115116
error = resultErrors?.join(", ")?.substring(0, 1000) || "Unable to verify provider";
116117
if (error.includes(`Request timeout while verifying ${type}.`)) {
117-
console.log(`Request timeout while verifying ${type}`);
118+
logger.debug(`Request timeout while verifying ${type}`);
118119
// If a request times out exit loop and return results so additional requests are not made
119120
break;
120121
}

identity/src/verifyDidChallenge.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { encode } from "multiformats/block";
77
import { sha256 } from "multiformats/hashes/sha2";
88
import { Cacao } from "@didtools/cacao";
99
import { ApiError } from "./serverUtils/apiError.js";
10+
import { logger } from "./logger.js";
1011

1112
class ChallengeMismatchError extends ApiError {
1213
constructor() {
@@ -79,7 +80,7 @@ const verifyAgeAndGetCacao = async (signedChallenge: SignedDidChallenge): Promis
7980
return cacao;
8081
// }
8182
} catch (e) {
82-
console.error(e);
83+
logger.error(e);
8384
}
8485
throw new CredentialTooOldError();
8586
};

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,8 @@
9393
"prettier --write"
9494
]
9595
},
96-
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
96+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
97+
"dependencies": {
98+
"pino": "^9.6.0"
99+
}
97100
}

0 commit comments

Comments
 (0)