Skip to content

Commit

Permalink
only clear mod component debug logs if logValues is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamlangford committed Oct 3, 2024
1 parent 5926ec2 commit 9ad3f0f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
16 changes: 11 additions & 5 deletions src/contentScript/contentScriptPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,17 @@ class ContentScriptPlatform extends PlatformBase {

override get debugger(): PlatformProtocol["debugger"] {
return {
async clear(componentId: UUID): Promise<void> {
await Promise.all([
traces.clear(componentId),
clearModComponentDebugLogs(componentId),
]);
async clear(
componentId: UUID,
{ logValues }: { logValues: boolean },
): Promise<void> {
const clearPromises = [traces.clear(componentId)];

if (logValues) {
clearPromises.push(clearModComponentDebugLogs(componentId));
}

await Promise.all(clearPromises);
},
traces: {
enter: traces.addEntry,
Expand Down
16 changes: 11 additions & 5 deletions src/extensionPages/extensionPagePlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ class ExtensionPagePlatform extends PlatformBase {
// Support tracing for bricks run in the sidebar and clearing logs in Page Editor/Extension Console. See PanelBody.tsx
override get debugger(): PlatformProtocol["debugger"] {
return {
async clear(componentId: UUID): Promise<void> {
await Promise.all([
traces.clear(componentId),
clearModComponentDebugLogs(componentId),
]);
async clear(
componentId: UUID,
{ logValues }: { logValues: boolean },
): Promise<void> {
const clearPromises = [traces.clear(componentId)];

if (logValues) {
clearPromises.push(clearModComponentDebugLogs(componentId));
}

await Promise.all(clearPromises);
},
traces: {
enter: traces.addEntry,
Expand Down
5 changes: 4 additions & 1 deletion src/platform/platformTypes/debuggerProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export interface DebuggerProtocol {
*
* @param componentId the mod component id
*/
clear: (componentId: UUID) => Promise<void>;
clear: (
componentId: UUID,
{ logValues }: { logValues: boolean },
) => Promise<void>;

traces: TraceProtocol;
}
16 changes: 11 additions & 5 deletions src/runtime/reducePipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ type RunBrickOptions = CommonOptions & {
trace: TraceMetadata;
};

async function getLogValues(
logValues: RunBrickOptions["logValues"] | undefined,
): Promise<boolean> {
const globalLoggingConfig = await getLoggingConfig();

return logValues ?? globalLoggingConfig.logValues ?? false;
}

/**
* Get the lexical environment for running a pipeline. Currently, we're just tracking on the pipeline arg itself.
* https://en.wikipedia.org/wiki/Closure_(computer_programming)
Expand Down Expand Up @@ -456,11 +464,9 @@ async function renderBrickArg(
): Promise<RenderedArgs> {
const { config, type } = resolvedConfig;

const globalLoggingConfig = await getLoggingConfig();

const {
// If logValues not provided explicitly, default to the global setting
logValues = globalLoggingConfig.logValues ?? false,
logValues = await getLogValues(options.logValues),
logger,
explicitArg,
explicitDataFlow,
Expand Down Expand Up @@ -637,7 +643,6 @@ async function applyReduceDefaults({
Partial<ReduceOptions>,
"modComponentRef"
>): Promise<ReduceOptions> {
const globalLoggingConfig = await getLoggingConfig();
const logger = providedLogger ?? new ConsoleLogger();

return {
Expand All @@ -652,7 +657,7 @@ async function applyReduceDefaults({
explicitDataFlow: false,
extendModVariable: false,
// If logValues not provided explicitly, default to the global setting
logValues: logValues ?? globalLoggingConfig.logValues ?? false,
logValues: await getLogValues(logValues),
// For stylistic consistency, default here instead of destructured parameters
branches: [],
// NOTE: do not set runId here. It should be set by the starter brick explicitly, or implicitly generated
Expand Down Expand Up @@ -960,6 +965,7 @@ export async function reduceModComponentPipeline(
// `await` promise to avoid race condition where the calls here delete entries from this call to reducePipeline
await platform.debugger.clear(
partialOptions.modComponentRef.modComponentId,
{ logValues: await getLogValues(partialOptions.logValues) },
);
} catch {
// NOP
Expand Down

0 comments on commit 9ad3f0f

Please sign in to comment.