MCPcopy
hub / github.com/Tencent/TSW / writeLog

Method writeLog

lib/core/logger/index.ts:114–153  ·  view source on GitHub ↗
(type: LogLevelStrings, str: string)

Source from the content-addressed store, hash-verified

112 }
113
114 public writeLog(type: LogLevelStrings, str: string): void {
115 const level = LOG_LEVEL[type];
116
117 // Drop log
118 if (level < this.logLevel) {
119 return;
120 }
121
122 const logStr = Logger.formatStr(str, type, {
123 levelLimit: this.logLevel
124 });
125
126 // Store log
127 Logger.fillBuffer(type, logStr);
128
129 if (this.winstonLogger) {
130 const winstonLogType = Logger.getWinstonType(type);
131 this.winstonLogger.log(`${winstonLogType}`, logStr);
132 }
133
134 if (isInspect()) {
135 // When started with inspect, log will send to 2 places
136 // 1. Local stdout
137 // 2. Remote(maybe chrome inspect window) inspect window
138
139 // Here for remote window
140 Logger.fillInspect(logStr, level);
141
142 const logWithColor = Logger.formatStr(str, type, {
143 levelLimit: this.logLevel,
144 color: true
145 });
146
147 // Here for local stdout, with color
148 Logger.fillStdout(logWithColor);
149 } else {
150 // Send to local stdout
151 Logger.fillStdout(logStr);
152 }
153 }
154
155 /**
156 * Convert TSW log level to winston log level

Callers 5

debugMethod · 0.95
infoMethod · 0.95
warnMethod · 0.95
errorMethod · 0.95
consoleHackFunction · 0.80

Calls 6

isInspectFunction · 0.85
formatStrMethod · 0.80
fillBufferMethod · 0.80
getWinstonTypeMethod · 0.80
fillInspectMethod · 0.80
fillStdoutMethod · 0.80

Tested by

no test coverage detected