Skip to content

Commit 0edcecf

Browse files
committed
prefix logging output
1 parent 8b94bec commit 0edcecf

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

dashi/src/lib/actions/helpers/configureLogging.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@ function logState(next: StoreState, prev: StoreState) {
2727
const delta = diff(prev, next);
2828
const nDiffs = delta.length;
2929
console.groupCollapsed(
30-
`state changed (${nDiffs} difference${nDiffs === 1 ? "" : "s"})`,
30+
`dashi: state changed (${nDiffs} difference${nDiffs === 1 ? "" : "s"})`,
3131
);
3232
delta.forEach(logDiff);
33-
console.debug("Details:", { prev, next, delta });
33+
console.debug("dashi: change details:", { prev, next, delta });
3434
console.groupEnd();
3535
}
3636

3737
function logDiff(v: Difference, index: number) {
3838
const wherePart = `%c${index + 1} %c${v.type} %c${v.path.join(".")}`;
3939
if (v.type === "CREATE") {
40-
console.log(wherePart, indexStyle, typeStyle, pathStyle, {
40+
console.debug("dashi:", wherePart, indexStyle, typeStyle, pathStyle, {
4141
value: v.value,
4242
});
4343
} else if (v.type === "CHANGE") {
44-
console.log(wherePart, indexStyle, typeStyle, pathStyle, {
44+
console.debug("dashi:", wherePart, indexStyle, typeStyle, pathStyle, {
4545
value: v.value,
4646
oldValue: v.oldValue,
4747
});
4848
} else if (v.type === "REMOVE") {
49-
console.log(wherePart, indexStyle, typeStyle, pathStyle, {
49+
console.debug("dashi:", wherePart, indexStyle, typeStyle, pathStyle, {
5050
oldValue: v.oldValue,
5151
});
5252
}

dashi/src/lib/actions/helpers/invokeCallbacks.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,27 @@ import { fetchCallback } from "@/lib/api/fetchCallback";
44
import { applyStateChangeRequests } from "@/lib/actions/helpers/applyStateChangeRequests";
55

66
export function invokeCallbacks(callbackRequests: CallbackRequest[]) {
7+
const { configuration } = store.getState();
8+
const shouldLog = configuration.logging?.enabled;
79
if (!callbackRequests.length) {
10+
if (shouldLog) {
11+
console.info(`dashi: invokeCallbacks - no requests`, callbackRequests);
12+
}
813
return;
914
}
10-
const { configuration } = store.getState();
1115
const invocationId = getInvocationId();
12-
if (import.meta.env.DEV) {
13-
console.debug(`invokeCallbacks (${invocationId})-->`, callbackRequests);
16+
if (shouldLog) {
17+
console.info(
18+
`dashi: invokeCallbacks (${invocationId})-->`,
19+
callbackRequests,
20+
);
1421
}
1522
fetchCallback(callbackRequests, configuration.api).then(
1623
(changeRequestsResult) => {
1724
if (changeRequestsResult.data) {
18-
if (import.meta.env.DEV) {
19-
console.debug(
20-
`invokeCallbacks <--(${invocationId})`,
25+
if (shouldLog) {
26+
console.info(
27+
`dashi: invokeCallbacks <--(${invocationId})`,
2128
changeRequestsResult.data,
2229
);
2330
}

0 commit comments

Comments
 (0)