mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
4.8.3 (#1654)
* Milvus (#1644) * feat: support regx * 4.8.3 test and fix (#1648) * perf: version tip * feat: sandbox support log * fix: debug component render * fix: share page header * fix: input guide auth * fix: iso viewport * remove file * fix: route url * feat: add debug timout * perf: reference select support trigger * perf: session code * perf: theme * perf: load milvus
This commit is contained in:
@@ -1,13 +1,35 @@
|
||||
import dayjs from 'dayjs';
|
||||
import chalk from 'chalk';
|
||||
|
||||
enum LogLevelEnum {
|
||||
debug = 'debug',
|
||||
info = 'info',
|
||||
warn = 'warn',
|
||||
error = 'error'
|
||||
}
|
||||
const logMap = {
|
||||
[LogLevelEnum.debug]: {
|
||||
levelLog: chalk.green('[Debug]')
|
||||
},
|
||||
[LogLevelEnum.info]: {
|
||||
levelLog: chalk.blue('[Info]')
|
||||
},
|
||||
[LogLevelEnum.warn]: {
|
||||
levelLog: chalk.yellow('[Warn]')
|
||||
},
|
||||
[LogLevelEnum.error]: {
|
||||
levelLog: chalk.red('[Error]')
|
||||
}
|
||||
};
|
||||
|
||||
/* add logger */
|
||||
export const addLog = {
|
||||
log(level: 'info' | 'warn' | 'error', msg: string, obj: Record<string, any> = {}) {
|
||||
log(level: LogLevelEnum, msg: string, obj: Record<string, any> = {}) {
|
||||
const stringifyObj = JSON.stringify(obj);
|
||||
const isEmpty = Object.keys(obj).length === 0;
|
||||
|
||||
console.log(
|
||||
`[${level.toLocaleUpperCase()}] ${dayjs().format('YYYY-MM-DD HH:mm:ss')} ${msg} ${
|
||||
`${logMap[level].levelLog} ${dayjs().format('YYYY-MM-DD HH:mm:ss')} ${msg} ${
|
||||
level !== 'error' && !isEmpty ? stringifyObj : ''
|
||||
}`
|
||||
);
|
||||
@@ -44,14 +66,17 @@ export const addLog = {
|
||||
});
|
||||
} catch (error) {}
|
||||
},
|
||||
debug(msg: string, obj?: Record<string, any>) {
|
||||
this.log(LogLevelEnum.debug, msg, obj);
|
||||
},
|
||||
info(msg: string, obj?: Record<string, any>) {
|
||||
this.log('info', msg, obj);
|
||||
this.log(LogLevelEnum.info, msg, obj);
|
||||
},
|
||||
warn(msg: string, obj?: Record<string, any>) {
|
||||
this.log('warn', msg, obj);
|
||||
this.log(LogLevelEnum.warn, msg, obj);
|
||||
},
|
||||
error(msg: string, error?: any) {
|
||||
this.log('error', msg, {
|
||||
this.log(LogLevelEnum.error, msg, {
|
||||
message: error?.message || error,
|
||||
stack: error?.stack,
|
||||
...(error?.config && {
|
||||
|
Reference in New Issue
Block a user