MCPcopy Create free account
hub / github.com/NomicFoundation/hardhat / createDebug

Function createDebug

packages/hardhat-utils/src/debug.ts:52–83  ·  view source on GitHub ↗
(namespace: string)

Source from the content-addressed store, hash-verified

50 * @returns Logger function, or a shared no-op if disabled.
51 */
52export function createDebug(namespace: string): DebugLogger {
53 if (!isEnabled(namespace, process.env.DEBUG ?? "")) {
54 return NOOP;
55 }
56
57 const colors = useColors();
58 const color = colors ? selectColor(namespace) : undefined;
59 const prefix =
60 color !== undefined
61 ? `\x1b[38;5;${color};1m ${namespace}\x1b[0m`
62 : ` ${namespace}`;
63 const suffixOpen = color !== undefined ? `\x1b[38;5;${color}m` : "";
64 const suffixClose = color !== undefined ? `\x1b[0m` : "";
65 let prev = 0;
66
67 const logger = (format: unknown, ...args: unknown[]): void => {
68 const now = Date.now();
69 const diff = prev === 0 ? 0 : now - prev;
70 prev = now;
71
72 const body =
73 args.length === 0 && typeof format === "string"
74 ? format
75 : formatWithOptions({ colors }, format, ...args);
76
77 process.stderr.write(
78 `${prefix} ${body} ${suffixOpen}+${diff}ms${suffixClose}\n`,
79 );
80 };
81
82 return Object.assign(logger, { enabled: true });
83}

Callers 15

handler.tsFile · 0.90
task-action.tsFile · 0.90
load-module.tsFile · 0.90
config-loading.tsFile · 0.90
banner-manager.tsFile · 0.90
mainFunction · 0.90
mainFunction · 0.90
init.tsFile · 0.90
transport.tsFile · 0.90
reporter.tsFile · 0.90
subprocess.tsFile · 0.90

Calls 3

isEnabledFunction · 0.85
useColorsFunction · 0.85
selectColorFunction · 0.85

Tested by

no test coverage detected