Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable log filtering with the DEBUG variable #7150

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion boxes/boxes/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"tty-browserify": "^0.0.1",
"typescript": "^5.0.4",
"util": "^0.12.5",
"webpack": "^5.88.2",
Expand Down
1 change: 0 additions & 1 deletion boxes/boxes/react/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default (_, argv) => ({
util: require.resolve('util/'),
stream: require.resolve('stream-browserify'),
string_decoder: require.resolve('string_decoder/'),
tty: require.resolve('tty-browserify'),
},
},
devServer: {
Expand Down
1 change: 0 additions & 1 deletion boxes/boxes/vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"html-webpack-plugin": "^5.6.0",
"stream-browserify": "^3.0.0",
"ts-loader": "^9.5.1",
"tty-browserify": "^0.0.1",
"typescript": "^5.0.4",
"util": "^0.12.5",
"webpack": "^5.90.1",
Expand Down
1 change: 0 additions & 1 deletion boxes/boxes/vanilla/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default (_, argv) => ({
util: require.resolve('util/'),
stream: require.resolve('stream-browserify'),
string_decoder: require.resolve('string_decoder/'),
tty: require.resolve('tty-browserify'),
},
},
devServer: {
Expand Down
1 change: 0 additions & 1 deletion boxes/contract-only/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"jest": "^29.6.4",
"stream-browserify": "^3.0.0",
"ts-loader": "^9.5.1",
"tty-browserify": "^0.0.1",
"typescript": "^5.0.4",
"util": "^0.12.5",
"webpack": "^5.90.1",
Expand Down
9 changes: 0 additions & 9 deletions boxes/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ __metadata:
ts-jest: "npm:^29.1.0"
ts-loader: "npm:^9.4.4"
ts-node: "npm:^10.9.1"
tty-browserify: "npm:^0.0.1"
typescript: "npm:^5.0.4"
util: "npm:^0.12.5"
webpack: "npm:^5.88.2"
Expand Down Expand Up @@ -133,7 +132,6 @@ __metadata:
html-webpack-plugin: "npm:^5.6.0"
stream-browserify: "npm:^3.0.0"
ts-loader: "npm:^9.5.1"
tty-browserify: "npm:^0.0.1"
typescript: "npm:^5.0.4"
util: "npm:^0.12.5"
webpack: "npm:^5.90.1"
Expand Down Expand Up @@ -8957,13 +8955,6 @@ __metadata:
languageName: node
linkType: hard

"tty-browserify@npm:^0.0.1":
version: 0.0.1
resolution: "tty-browserify@npm:0.0.1"
checksum: 5e34883388eb5f556234dae75b08e069b9e62de12bd6d87687f7817f5569430a6dfef550b51dbc961715ae0cd0eb5a059e6e3fc34dc127ea164aa0f9b5bb033d
languageName: node
linkType: hard

"type-check@npm:^0.4.0, type-check@npm:~0.4.0":
version: 0.4.0
resolution: "type-check@npm:0.4.0"
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ services:
# need to run bb for proofs and bb is only built for x86
platform: linux/amd64
environment:
LOG_LEVEL: info
DEBUG: aztec:*
LOG_LEVEL: ${LOG_LEVEL:-info}
DEBUG: ${DEBUG:-aztec:*,-json-rpc:*,-aztec:circuits:artifact_hash,-aztec:randomness_singleton}
DEBUG_COLORS: 1
CHAIN_ID: 31337
VERSION: 1
Expand Down Expand Up @@ -34,8 +34,8 @@ services:
# need to run bb for proofs and bb is only built for x86
platform: linux/amd64
environment:
LOG_LEVEL: info
DEBUG: aztec:*
LOG_LEVEL: ${LOG_LEVEL:-info}
DEBUG: ${DEBUG:-aztec:*,-json-rpc:*,-aztec:circuits:artifact_hash,-aztec:randomness_singleton,-aztec:avm_simulator:*}
DEBUG_COLORS: 1
CHAIN_ID: 31337
VERSION: 1
Expand Down
1 change: 0 additions & 1 deletion yarn-project/aztec.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
"stream-browserify": "^3.0.0",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"tty-browserify": "^0.0.1",
"typescript": "^5.0.4",
"util": "^0.12.5",
"webpack": "^5.88.2",
Expand Down
1 change: 0 additions & 1 deletion yarn-project/aztec.js/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export default {
buffer: require.resolve('buffer/'),
util: require.resolve('util/'),
stream: require.resolve('stream-browserify'),
tty: require.resolve('tty-browserify'),
},
},
};
1 change: 0 additions & 1 deletion yarn-project/end-to-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"tty-browserify": "^0.0.1",
"typescript": "^5.0.4",
"util": "^0.12.5",
"viem": "^2.7.15",
Expand Down
1 change: 0 additions & 1 deletion yarn-project/end-to-end/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default {
buffer: require.resolve('buffer/'),
util: require.resolve('util/'),
stream: require.resolve('stream-browserify'),
tty: require.resolve('tty-browserify'),
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class RandomnessSingleton {
private readonly log = createDebugLogger('aztec:randomness_singleton'),
) {
if (seed !== undefined) {
this.log.verbose(`Using pseudo-randomness with seed: ${seed}`);
this.log.debug(`Using pseudo-randomness with seed: ${seed}`);
this.counter = seed;
} else {
this.log.verbose('Using true randomness');
this.log.debug('Using true randomness');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class JsonRpcServer {
private objectClassMap: JsonClassConverterInput,
/** List of methods to disallow from calling remotely */
public readonly disallowedMethods: string[] = [],
private log = createDebugLogger('aztec:foundation:json-rpc:server'),
private log = createDebugLogger('json-rpc:server'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move all json-rpc loggers to their own namespace (previously only the client used it, while the serve was part of foundation).

) {
this.proxy = new JsonProxy(handler, stringClassMap, objectClassMap);
}
Expand Down Expand Up @@ -226,7 +226,7 @@ export type ServerList = {
*/
export function createNamespacedJsonRpcServer(
servers: ServerList,
log = createDebugLogger('aztec:foundation:json-rpc:multi-server'),
log = createDebugLogger('json-rpc:multi-server'),
): JsonRpcServer {
const handler = {} as any;
const disallowedMethods: string[] = [];
Expand Down
43 changes: 5 additions & 38 deletions yarn-project/foundation/src/log/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import debug from 'debug';
import isNode from 'detect-node';
import { isatty } from 'tty';

import { type LogData, type LogFn } from './log_fn.js';

Expand All @@ -15,6 +13,9 @@ export type LogLevel = (typeof LogLevels)[number];
const envLogLevel = process.env.LOG_LEVEL?.toLowerCase() as LogLevel;
const currentLevel = LogLevels.includes(envLogLevel) ? envLogLevel : DefaultLogLevel;

const namespaces = process.env.DEBUG ?? 'aztec:*';
debug.enable(namespaces);

/** Log function that accepts an exception object */
type ErrorLogFn = (msg: string, err?: Error | unknown, data?: LogData) => void;

Expand All @@ -38,9 +39,6 @@ export type DebugLogger = Logger;
*/
export function createDebugLogger(name: string): DebugLogger {
const debugLogger = debug(name);
if (currentLevel === 'debug') {
debugLogger.enabled = true;
}

const logger = {
silent: () => {},
Expand Down Expand Up @@ -78,42 +76,11 @@ function logWithDebug(debug: debug.Debugger, level: LogLevel, msg: string, data?
}

msg = data ? `${msg} ${fmtLogData(data)}` : msg;
if (debug.enabled) {
if (level !== 'debug') {
msg = `${level.toUpperCase()} ${msg}`;
}
debug(msg);
} else if (LogLevels.indexOf(level) <= LogLevels.indexOf(currentLevel)) {
printLog(`${getPrefix(debug, level)} ${msg}`);
if (debug.enabled && LogLevels.indexOf(level) <= LogLevels.indexOf(currentLevel)) {
debug('[%s] %s', level.toUpperCase(), msg);
}
}

/**
* Returns a log prefix that emulates that of npm debug. Uses colors if in node and in a tty.
* @param debugLogger - Instance of npm debug logger.
* @param level - Intended log level (printed out if strictly above current log level).
* @returns Log prefix.
*/
function getPrefix(debugLogger: debug.Debugger, level: LogLevel) {
const levelLabel = currentLevel !== level ? ` ${level.toUpperCase()}` : '';
const prefix = `${debugLogger.namespace.replace(/^aztec:/, '')}${levelLabel}`;
if ((!isNode || !isatty(process.stderr.fd)) && !process.env.DEBUG_COLORS) {
return prefix;
}
const colorIndex = debug.selectColor(debugLogger.namespace) as number;
const colorCode = '\u001B[3' + (colorIndex < 8 ? colorIndex : '8;5;' + colorIndex);
return ` ${colorCode};1m${prefix}\u001B[0m`;
}

/**
* Outputs to console error.
* @param msg - What to log.
*/
function printLog(msg: string) {
// eslint-disable-next-line no-console
isNode ? process.stderr.write(msg + '\n') : console.error(msg);
}

/**
* Concatenates a log message and an exception.
* @param msg - Log message
Expand Down
9 changes: 0 additions & 9 deletions yarn-project/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ __metadata:
ts-loader: ^9.4.4
ts-node: ^10.9.1
tslib: ^2.4.0
tty-browserify: ^0.0.1
typescript: ^5.0.4
util: ^0.12.5
webpack: ^5.88.2
Expand Down Expand Up @@ -464,7 +463,6 @@ __metadata:
ts-loader: ^9.4.4
ts-node: ^10.9.1
tslib: ^2.4.0
tty-browserify: ^0.0.1
typescript: ^5.0.4
util: ^0.12.5
viem: ^2.7.15
Expand Down Expand Up @@ -13608,13 +13606,6 @@ __metadata:
languageName: node
linkType: hard

"tty-browserify@npm:^0.0.1":
version: 0.0.1
resolution: "tty-browserify@npm:0.0.1"
checksum: 93b745d43fa5a7d2b948fa23be8d313576d1d884b48acd957c07710bac1c0d8ac34c0556ad4c57c73d36e11741763ef66b3fb4fb97b06b7e4d525315a3cd45f5
languageName: node
linkType: hard

"type-check@npm:^0.4.0, type-check@npm:~0.4.0":
version: 0.4.0
resolution: "type-check@npm:0.4.0"
Expand Down
Loading