diff --git a/yarn-project/foundation/src/log/logger.ts b/yarn-project/foundation/src/log/logger.ts index 0f245882550..d008774f182 100644 --- a/yarn-project/foundation/src/log/logger.ts +++ b/yarn-project/foundation/src/log/logger.ts @@ -36,22 +36,27 @@ export type DebugLogger = Logger; * If DEBUG="[module]" env is set, will enable debug logging if the module matches. * Uses npm debug for debug level and console.error for other levels. * @param name - Name of the module. + * @param taggedLogData - Additional data to include in the log message. + * @usage createDebugLogger('aztec:validator', {validatorAddress: '0x1234...'}); + * // will always add the validator address to the log labels * @returns A debug logger. */ -export function createDebugLogger(name: string): DebugLogger { + + +export function createDebugLogger(name: string, taggedLogData?: LogData ): DebugLogger { const debugLogger = debug(name); + if (currentLevel === 'debug') debugLogger.enabled = true; const logger = { silent: () => {}, - error: (msg: string, err?: unknown, data?: LogData) => logWithDebug(debugLogger, 'error', fmtErr(msg, err), data), - warn: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'warn', msg, data), - info: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'info', msg, data), - verbose: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'verbose', msg, data), - debug: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, data), + error: (...args: any[]) => logWithDebug(debugLogger, 'error', {...args, ...taggedLogData}), + warn: (...args: any[]) => logWithDebug(debugLogger, 'warn', {...args, ...taggedLogData}), + info: (...args: any[]) => logWithDebug(debugLogger, 'info', {...args, ...taggedLogData}), + verbose: (...args: any[]) => logWithDebug(debugLogger, 'verbose', {...args, ...taggedLogData}), + debug: (...args: any[]) => logWithDebug(debugLogger, 'debug', {...args, ...taggedLogData}), }; - return Object.assign((msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, data), logger); + return Object.assign((...args: any[]) => logWithDebug(debugLogger, 'debug', {...args, ...taggedLogData}), logger); } - /** A callback to capture all logs. */ export type LogHandler = (level: LogLevel, namespace: string, msg: string, data?: LogData) => void; diff --git a/yarn-project/validator-client/src/key_store/interface.ts b/yarn-project/validator-client/src/key_store/interface.ts index 2b96c90377b..9752f64f85d 100644 --- a/yarn-project/validator-client/src/key_store/interface.ts +++ b/yarn-project/validator-client/src/key_store/interface.ts @@ -6,6 +6,14 @@ import { type Signature } from '@aztec/foundation/eth-signature'; * A keystore interface that can be replaced with a local keystore / remote signer service */ export interface ValidatorKeyStore { + + /** + * Get the address of the signer + * + * @returns the address + */ + getAddress(): string; + sign(message: Buffer32): Promise; /** * Flavor of sign message that followed EIP-712 eth signed message prefix diff --git a/yarn-project/validator-client/src/key_store/local_key_store.ts b/yarn-project/validator-client/src/key_store/local_key_store.ts index 736ee361a45..75c7bd9f1c2 100644 --- a/yarn-project/validator-client/src/key_store/local_key_store.ts +++ b/yarn-project/validator-client/src/key_store/local_key_store.ts @@ -16,6 +16,15 @@ export class LocalKeyStore implements ValidatorKeyStore { this.signer = new Secp256k1Signer(privateKey); } + /** + * Get the address of the signer + * + * @returns the address + */ + public getAddress() { + return this.signer.address; + } + /** * Sign a message with the keystore private key * diff --git a/yarn-project/validator-client/src/validator.ts b/yarn-project/validator-client/src/validator.ts index 0124029c17b..a3fd67270b5 100644 --- a/yarn-project/validator-client/src/validator.ts +++ b/yarn-project/validator-client/src/validator.ts @@ -38,7 +38,7 @@ export class ValidatorClient implements Validator { private p2pClient: P2P, private attestationPoolingIntervalMs: number, private attestationWaitTimeoutMs: number, - private log = createDebugLogger('aztec:validator'), + private log = createDebugLogger('aztec:validator', {validatorAddress: keyStore.getAddress()}), ) { //TODO: We need to setup and store all of the currently active validators https://github.com/AztecProtocol/aztec-packages/issues/7962