51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import moment from "moment";
|
|
|
|
const getTimeStamp = (): string => {
|
|
const dt = moment().format("yyyy-MM-DD HH:mm:ss");
|
|
return dt;
|
|
};
|
|
|
|
const info = (namespace: string, message: string, object?: any) => {
|
|
if (object) {
|
|
console.log(
|
|
`[${getTimeStamp()}] [INFO] [${namespace}] [${message}]`,
|
|
object
|
|
);
|
|
} else {
|
|
console.log(`[${getTimeStamp()}] [INFO] [${namespace}] [${message}]`);
|
|
}
|
|
};
|
|
|
|
const warning = (namespace: string, message: string, object?: any) => {
|
|
if (object) {
|
|
console.log(
|
|
`[${getTimeStamp()}] [WARNING] [${namespace}] [${message}]`,
|
|
object
|
|
);
|
|
} else {
|
|
console.log(
|
|
`[${getTimeStamp()}] [WARNING] [${namespace}] [${message}]`
|
|
);
|
|
}
|
|
};
|
|
|
|
const error = (namespace: string, message: string, object?: any) => {
|
|
if (object) {
|
|
console.log(
|
|
`[${getTimeStamp()}] [ERROR] [${namespace}] [${message}]`,
|
|
object
|
|
);
|
|
} else {
|
|
console.log(`[${getTimeStamp()}] [ERROR] [${namespace}] [${message}]`);
|
|
}
|
|
};
|
|
|
|
const delay = (time: number) => new Promise(res => setTimeout(res, time));
|
|
|
|
export default {
|
|
info,
|
|
warning,
|
|
error,
|
|
delay,
|
|
};
|