core: send: 区分远端错误与本地错误

This commit is contained in:
undefined committed 2021-02-28 13:28:01 +08:00
1 parent 6f96e7fa9e
commit f2fbbb8af9
4 files changed
+29 -10

No files matched your search

+3 -2
View File
@@ -3,7 +3,7 @@ import { argv } from 'yargs';
import { Time } from './utils';
const instances: Record<string, Logger> = {};
type LogFunction = (format: any, ...param: any[]) => void;
type LogFunction = (format: any, ...param: any[]) => boolean;
type LogType = 'success' | 'error' | 'info' | 'warn' | 'debug';
export interface Logger extends Record<LogType, LogFunction> { }
export class Logger {
@@ -37,10 +37,11 @@ export class Logger {
private createMethod(name: LogType, prefix: string, minLevel: number) {
this[name] = (...args: [any, ...any[]]) => {
if (this.level < minLevel) return;
if (this.level < minLevel) return false;
const msg = `${prefix} ${this.name} ${this.format(...args)}`;
if (process.send) process.send({ event: 'message/log', payload: [msg] });
else global.Hydro.service.bus.parallel('message/log', msg);
return true;
};
}