* fix: updated skip functionality * update: type of logs to add occurence count * update: reducer function to merge the new logs * update: added dependance on last log's occurence count * add: UI to show the occurence badge * fix: added null check for dependency array * update: omit occurence from compare fn * update: changed function call to store logs array directly * update: moved from saving logs one by one to array * fix: replaced forEach with reduce * test: added functions for console log grouping * feat: updated warning grouping color * update: moved function to reducer file for jest tests
115 lines
2.3 KiB
TypeScript
115 lines
2.3 KiB
TypeScript
import {
|
|
addErrorLogInit,
|
|
debuggerLog,
|
|
debuggerLogInit,
|
|
deleteErrorLogInit,
|
|
} from "actions/debuggerActions";
|
|
import { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
|
|
import {
|
|
Severity,
|
|
LogActionPayload,
|
|
Log,
|
|
LOG_CATEGORY,
|
|
} from "entities/AppsmithConsole";
|
|
import moment from "moment";
|
|
import store from "store";
|
|
import AnalyticsUtil from "./AnalyticsUtil";
|
|
|
|
function dispatchAction(action: ReduxAction<unknown>) {
|
|
store.dispatch(action);
|
|
}
|
|
|
|
function log(ev: Log) {
|
|
if (ev.category === LOG_CATEGORY.USER_GENERATED) {
|
|
AnalyticsUtil.logEvent("CONSOLE_LOG_CREATED", {
|
|
entityName: ev.source?.name,
|
|
entityType: ev.source?.type,
|
|
});
|
|
}
|
|
dispatchAction(debuggerLogInit(ev));
|
|
}
|
|
|
|
function getTimeStamp() {
|
|
return moment().format("hh:mm:ss");
|
|
}
|
|
|
|
function addLogs(logs: Log[]) {
|
|
dispatchAction(debuggerLog(logs));
|
|
}
|
|
|
|
function info(
|
|
ev: LogActionPayload,
|
|
timestamp = getTimeStamp(),
|
|
category = LOG_CATEGORY.PLATFORM_GENERATED,
|
|
) {
|
|
log({
|
|
...ev,
|
|
severity: Severity.INFO,
|
|
timestamp,
|
|
category,
|
|
occurrenceCount: 1,
|
|
});
|
|
}
|
|
|
|
function warning(
|
|
ev: LogActionPayload,
|
|
timestamp = getTimeStamp(),
|
|
category = LOG_CATEGORY.PLATFORM_GENERATED,
|
|
) {
|
|
log({
|
|
...ev,
|
|
severity: Severity.WARNING,
|
|
timestamp,
|
|
category,
|
|
occurrenceCount: 1,
|
|
});
|
|
}
|
|
|
|
// This is used to show a log as an error
|
|
// NOTE: These logs won't appear in the errors tab
|
|
// To add errors to the errors tab use the addError method.
|
|
function error(
|
|
ev: LogActionPayload,
|
|
timestamp = getTimeStamp(),
|
|
category = LOG_CATEGORY.PLATFORM_GENERATED,
|
|
) {
|
|
log({
|
|
...ev,
|
|
severity: Severity.ERROR,
|
|
timestamp,
|
|
category,
|
|
occurrenceCount: 1,
|
|
});
|
|
}
|
|
|
|
// This is used to add an error to the errors tab
|
|
function addError(
|
|
payload: LogActionPayload,
|
|
severity = Severity.ERROR,
|
|
category = LOG_CATEGORY.PLATFORM_GENERATED,
|
|
) {
|
|
dispatchAction(
|
|
addErrorLogInit({
|
|
...payload,
|
|
severity: severity,
|
|
timestamp: getTimeStamp(),
|
|
category,
|
|
occurrenceCount: 1,
|
|
}),
|
|
);
|
|
}
|
|
|
|
// This is used to remove an error from the errors tab
|
|
function deleteError(id: string, analytics?: Log["analytics"]) {
|
|
dispatchAction(deleteErrorLogInit(id, analytics));
|
|
}
|
|
|
|
export default {
|
|
addLogs,
|
|
info,
|
|
warning,
|
|
error,
|
|
addError,
|
|
deleteError,
|
|
};
|