diff --git a/packages/opendesign/src/_utils/log.ts b/packages/opendesign/src/_utils/log.ts new file mode 100644 index 0000000000000000000000000000000000000000..903fd9e64af4074709399f7f0b28899a8e539612 --- /dev/null +++ b/packages/opendesign/src/_utils/log.ts @@ -0,0 +1,48 @@ +const logFunction = { + info: console.info, + warn: console.warn, + error: console.error, +}; + +export type LogLevel = keyof typeof logFunction; + +function printLog(level: LogLevel, ...msg: any[]) { + const fn = logFunction[level]; + if (fn) { + fn(...msg); + } +} + +export class Log { + prefix: string; + constructor(namespace?: string) { + this.prefix = ''; + if (namespace) { + this.prefix = `[${namespace}]`; + } + } + info(...msg: any[]) { + if (this.prefix) { + msg.unshift(this.prefix); + } + printLog('info', ...msg); + } + + warn(...msg: any[]) { + if (this.prefix) { + msg.unshift(this.prefix); + } + printLog('warn', ...msg); + } + + error(...msg: any[]) { + if (this.prefix) { + msg.unshift(this.prefix); + } + printLog('error', ...msg); + } +} + +const logger = new Log(); + +export default logger; diff --git a/packages/opendesign/src/flex/OFlex.vue b/packages/opendesign/src/flex/OFlex.vue index 6dbb2942afeadfcb043cdd41220d129c383c0144..276ba6b6bd76b85d7a7d97ec596d5388ce74a241 100644 --- a/packages/opendesign/src/flex/OFlex.vue +++ b/packages/opendesign/src/flex/OFlex.vue @@ -1,4 +1,5 @@