2021-08-16 11:03:27 +00:00
|
|
|
import {
|
|
|
|
|
addErrorLogInit,
|
2022-09-16 19:18:54 +00:00
|
|
|
debuggerLog,
|
2021-08-16 11:03:27 +00:00
|
|
|
debuggerLogInit,
|
|
|
|
|
deleteErrorLogInit,
|
|
|
|
|
} from "actions/debuggerActions";
|
2022-04-12 10:50:01 +00:00
|
|
|
import { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
|
2022-09-04 11:58:05 +00:00
|
|
|
import {
|
|
|
|
|
Severity,
|
|
|
|
|
LogActionPayload,
|
|
|
|
|
Log,
|
|
|
|
|
LOG_CATEGORY,
|
|
|
|
|
} from "entities/AppsmithConsole";
|
2021-04-23 13:50:55 +00:00
|
|
|
import moment from "moment";
|
|
|
|
|
import store from "store";
|
2022-09-04 11:58:05 +00:00
|
|
|
import AnalyticsUtil from "./AnalyticsUtil";
|
2021-02-03 13:16:48 +00:00
|
|
|
|
2021-08-16 11:03:27 +00:00
|
|
|
function dispatchAction(action: ReduxAction<unknown>) {
|
|
|
|
|
store.dispatch(action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function log(ev: Log) {
|
2022-09-04 11:58:05 +00:00
|
|
|
if (ev.category === LOG_CATEGORY.USER_GENERATED) {
|
|
|
|
|
AnalyticsUtil.logEvent("CONSOLE_LOG_CREATED", {
|
|
|
|
|
entityName: ev.source?.name,
|
|
|
|
|
entityType: ev.source?.type,
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-08-16 11:03:27 +00:00
|
|
|
dispatchAction(debuggerLogInit(ev));
|
2021-02-03 13:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-23 13:50:55 +00:00
|
|
|
function getTimeStamp() {
|
|
|
|
|
return moment().format("hh:mm:ss");
|
2021-02-03 13:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-16 19:18:54 +00:00
|
|
|
function addLogs(logs: Log[]) {
|
|
|
|
|
dispatchAction(debuggerLog(logs));
|
2022-09-04 11:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function info(
|
|
|
|
|
ev: LogActionPayload,
|
|
|
|
|
timestamp = getTimeStamp(),
|
|
|
|
|
category = LOG_CATEGORY.PLATFORM_GENERATED,
|
|
|
|
|
) {
|
2021-04-23 13:50:55 +00:00
|
|
|
log({
|
|
|
|
|
...ev,
|
|
|
|
|
severity: Severity.INFO,
|
2022-09-04 11:58:05 +00:00
|
|
|
timestamp,
|
|
|
|
|
category,
|
2022-09-19 06:29:04 +00:00
|
|
|
occurrenceCount: 1,
|
2021-04-23 13:50:55 +00:00
|
|
|
});
|
2021-02-03 13:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-04 11:58:05 +00:00
|
|
|
function warning(
|
|
|
|
|
ev: LogActionPayload,
|
|
|
|
|
timestamp = getTimeStamp(),
|
|
|
|
|
category = LOG_CATEGORY.PLATFORM_GENERATED,
|
|
|
|
|
) {
|
2021-04-23 13:50:55 +00:00
|
|
|
log({
|
|
|
|
|
...ev,
|
|
|
|
|
severity: Severity.WARNING,
|
2022-09-04 11:58:05 +00:00
|
|
|
timestamp,
|
|
|
|
|
category,
|
2022-09-19 06:29:04 +00:00
|
|
|
occurrenceCount: 1,
|
2021-04-23 13:50:55 +00:00
|
|
|
});
|
2021-02-03 13:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-16 11:03:27 +00:00
|
|
|
// 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.
|
2022-09-04 11:58:05 +00:00
|
|
|
function error(
|
|
|
|
|
ev: LogActionPayload,
|
|
|
|
|
timestamp = getTimeStamp(),
|
|
|
|
|
category = LOG_CATEGORY.PLATFORM_GENERATED,
|
|
|
|
|
) {
|
2021-04-23 13:50:55 +00:00
|
|
|
log({
|
|
|
|
|
...ev,
|
|
|
|
|
severity: Severity.ERROR,
|
2022-09-04 11:58:05 +00:00
|
|
|
timestamp,
|
|
|
|
|
category,
|
2022-09-19 06:29:04 +00:00
|
|
|
occurrenceCount: 1,
|
2021-04-23 13:50:55 +00:00
|
|
|
});
|
2021-02-03 13:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-16 11:03:27 +00:00
|
|
|
// This is used to add an error to the errors tab
|
2022-09-04 11:58:05 +00:00
|
|
|
function addError(
|
|
|
|
|
payload: LogActionPayload,
|
|
|
|
|
severity = Severity.ERROR,
|
|
|
|
|
category = LOG_CATEGORY.PLATFORM_GENERATED,
|
|
|
|
|
) {
|
2021-08-16 11:03:27 +00:00
|
|
|
dispatchAction(
|
|
|
|
|
addErrorLogInit({
|
|
|
|
|
...payload,
|
2021-08-26 04:45:17 +00:00
|
|
|
severity: severity,
|
2021-08-16 11:03:27 +00:00
|
|
|
timestamp: getTimeStamp(),
|
2022-09-04 11:58:05 +00:00
|
|
|
category,
|
2022-09-19 06:29:04 +00:00
|
|
|
occurrenceCount: 1,
|
2021-08-16 11:03:27 +00:00
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is used to remove an error from the errors tab
|
|
|
|
|
function deleteError(id: string, analytics?: Log["analytics"]) {
|
|
|
|
|
dispatchAction(deleteErrorLogInit(id, analytics));
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-23 13:50:55 +00:00
|
|
|
export default {
|
2022-09-16 19:18:54 +00:00
|
|
|
addLogs,
|
2021-04-23 13:50:55 +00:00
|
|
|
info,
|
|
|
|
|
warning,
|
|
|
|
|
error,
|
2021-08-16 11:03:27 +00:00
|
|
|
addError,
|
|
|
|
|
deleteError,
|
2021-04-23 13:50:55 +00:00
|
|
|
};
|