PromucFlow_constructor/app/client/src/utils/AppsmithConsole.ts

73 lines
1.5 KiB
TypeScript
Raw Normal View History

import {
addErrorLogInit,
debuggerLogInit,
deleteErrorLogInit,
} from "actions/debuggerActions";
import { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
import { Severity, LogActionPayload, Log } from "entities/AppsmithConsole";
2021-04-23 13:50:55 +00:00
import moment from "moment";
import store from "store";
function dispatchAction(action: ReduxAction<unknown>) {
store.dispatch(action);
}
function log(ev: Log) {
dispatchAction(debuggerLogInit(ev));
}
2021-04-23 13:50:55 +00:00
function getTimeStamp() {
return moment().format("hh:mm:ss");
}
2021-04-23 13:50:55 +00:00
function info(ev: LogActionPayload) {
log({
...ev,
severity: Severity.INFO,
timestamp: getTimeStamp(),
});
}
2021-04-23 13:50:55 +00:00
function warning(ev: LogActionPayload) {
log({
...ev,
severity: Severity.WARNING,
timestamp: getTimeStamp(),
});
}
// 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(),
});
}
// This is used to add an error to the errors tab
function addError(payload: LogActionPayload, severity = Severity.ERROR) {
dispatchAction(
addErrorLogInit({
...payload,
severity: severity,
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,
addError,
deleteError,
2021-04-23 13:50:55 +00:00
};