mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
feat: enhance date formatting options to include seconds in logs
This commit is contained in:
@@ -819,26 +819,37 @@ export default class OneUptimeDate {
|
||||
return moment(date).isBefore(endDate);
|
||||
}
|
||||
|
||||
public static getCurrentDateAsFormattedString(): string {
|
||||
return this.getDateAsFormattedString(new Date());
|
||||
public static getCurrentDateAsFormattedString(options?: {
|
||||
onlyShowDate?: boolean;
|
||||
showSeconds?: boolean;
|
||||
}): string {
|
||||
return this.getDateAsFormattedString(new Date(), options);
|
||||
}
|
||||
|
||||
|
||||
public static getDateAsFormattedString(
|
||||
date: string | Date,
|
||||
onlyShowDate?: boolean,
|
||||
options?: {
|
||||
onlyShowDate?: boolean;
|
||||
showSeconds?: boolean;
|
||||
}
|
||||
): string {
|
||||
date = this.fromString(date);
|
||||
|
||||
let formatstring: string = "MMM DD YYYY, HH:mm";
|
||||
|
||||
if (onlyShowDate) {
|
||||
if(options?.showSeconds){
|
||||
formatstring = "MMM DD YYYY, HH:mm:ss";
|
||||
}
|
||||
|
||||
if (options?.onlyShowDate) {
|
||||
formatstring = "MMM DD, YYYY";
|
||||
}
|
||||
|
||||
return (
|
||||
moment(date).format(formatstring) +
|
||||
" " +
|
||||
(onlyShowDate ? "" : this.getCurrentTimezoneString())
|
||||
(options?.onlyShowDate ? "" : this.getCurrentTimezoneString())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,9 @@ RunCron(
|
||||
workflowStatus: WorkflowStatus.Error,
|
||||
logs: `${
|
||||
stalledWorkflowLog.logs
|
||||
} \n ${OneUptimeDate.getCurrentDateAsFormattedString()}: Workflow was not picked up by the runner and has timed out.`,
|
||||
} \n ${OneUptimeDate.getCurrentDateAsFormattedString({
|
||||
showSeconds: true,
|
||||
})}: Workflow was not picked up by the runner and has timed out.`,
|
||||
},
|
||||
props: {
|
||||
isRoot: true,
|
||||
|
||||
@@ -100,7 +100,9 @@ export default class QueueWorkflow {
|
||||
runLog.projectId = workflow.projectId;
|
||||
runLog.workflowStatus = WorkflowStatus.WorkflowCountExceeded;
|
||||
runLog.logs =
|
||||
OneUptimeDate.getCurrentDateAsFormattedString() +
|
||||
OneUptimeDate.getCurrentDateAsFormattedString({
|
||||
showSeconds: true,
|
||||
}) +
|
||||
": Workflow cannot run because subscription is unpaid.";
|
||||
|
||||
await WorkflowLogService.create({
|
||||
@@ -135,7 +137,9 @@ export default class QueueWorkflow {
|
||||
runLog.projectId = workflow.projectId;
|
||||
runLog.workflowStatus = WorkflowStatus.WorkflowCountExceeded;
|
||||
runLog.logs =
|
||||
OneUptimeDate.getCurrentDateAsFormattedString() +
|
||||
OneUptimeDate.getCurrentDateAsFormattedString({
|
||||
showSeconds: true,
|
||||
}) +
|
||||
`: Workflow cannot run because it already ran ${workflowCount.toNumber()} in the last 30 days. Your current plan limit is ${
|
||||
WorkflowPlan[projectPlan.plan]
|
||||
}`;
|
||||
@@ -160,7 +164,9 @@ export default class QueueWorkflow {
|
||||
runLog.projectId = workflow.projectId;
|
||||
runLog.workflowStatus = WorkflowStatus.Scheduled;
|
||||
runLog.logs =
|
||||
OneUptimeDate.getCurrentDateAsFormattedString() +
|
||||
OneUptimeDate.getCurrentDateAsFormattedString({
|
||||
showSeconds: true,
|
||||
}) +
|
||||
`: Workflow ${workflowId.toString()} Scheduled.`;
|
||||
|
||||
workflowLog = await WorkflowLogService.create({
|
||||
|
||||
@@ -107,7 +107,9 @@ export default class RunWorkflow {
|
||||
runLog.projectId = workflow.projectId!;
|
||||
runLog.workflowStatus = WorkflowStatus.Scheduled;
|
||||
runLog.logs =
|
||||
OneUptimeDate.getCurrentDateAsFormattedString() +
|
||||
OneUptimeDate.getCurrentDateAsFormattedString({
|
||||
showSeconds: true,
|
||||
}) +
|
||||
`: Workflow ${runProps.workflowId.toString()} Scheduled.`;
|
||||
|
||||
runProps.workflowLogId = (
|
||||
@@ -485,11 +487,15 @@ export default class RunWorkflow {
|
||||
|
||||
if (typeof data === "string") {
|
||||
this.logs.push(
|
||||
OneUptimeDate.getCurrentDateAsFormattedString() + ": " + data,
|
||||
OneUptimeDate.getCurrentDateAsFormattedString({
|
||||
showSeconds: true,
|
||||
}) + ": " + data,
|
||||
);
|
||||
} else {
|
||||
this.logs.push(
|
||||
OneUptimeDate.getCurrentDateAsFormattedString() +
|
||||
OneUptimeDate.getCurrentDateAsFormattedString({
|
||||
showSeconds: true,
|
||||
}) +
|
||||
": " +
|
||||
JSON.stringify(data),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user