2021-08-16 11:03:27 +00:00
|
|
|
import {
|
|
|
|
|
addErrorLogInit,
|
|
|
|
|
debuggerLogInit,
|
|
|
|
|
deleteErrorLogInit,
|
|
|
|
|
} from "actions/debuggerActions";
|
2022-04-12 10:50:01 +00:00
|
|
|
import { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
|
2021-08-16 11:03:27 +00:00
|
|
|
import { Severity, LogActionPayload, Log } from "entities/AppsmithConsole";
|
2021-04-23 13:50:55 +00:00
|
|
|
import moment from "moment";
|
|
|
|
|
import store from "store";
|
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) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-04-23 13:50:55 +00:00
|
|
|
function info(ev: LogActionPayload) {
|
|
|
|
|
log({
|
|
|
|
|
...ev,
|
|
|
|
|
severity: Severity.INFO,
|
|
|
|
|
timestamp: getTimeStamp(),
|
|
|
|
|
});
|
2021-02-03 13:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-23 13:50:55 +00:00
|
|
|
function warning(ev: LogActionPayload) {
|
|
|
|
|
log({
|
|
|
|
|
...ev,
|
|
|
|
|
severity: Severity.WARNING,
|
|
|
|
|
timestamp: getTimeStamp(),
|
|
|
|
|
});
|
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.
|
2021-04-23 13:50:55 +00:00
|
|
|
function error(ev: LogActionPayload) {
|
|
|
|
|
log({
|
|
|
|
|
...ev,
|
|
|
|
|
severity: Severity.ERROR,
|
|
|
|
|
timestamp: getTimeStamp(),
|
|
|
|
|
});
|
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
|
2021-08-26 04:45:17 +00:00
|
|
|
function addError(payload: LogActionPayload, severity = Severity.ERROR) {
|
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(),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
|
info,
|
|
|
|
|
warning,
|
|
|
|
|
error,
|
2021-08-16 11:03:27 +00:00
|
|
|
addError,
|
|
|
|
|
deleteError,
|
2021-04-23 13:50:55 +00:00
|
|
|
};
|