8000 console, feat: support complex parameters in console.trace. · fibjs/fibjs@cd69b3c · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit cd69b3c

Browse files
committed
console, feat: support complex parameters in console.trace.
1 parent 7739a73 commit cd69b3c

File tree

4 files changed

+96
-68
lines changed

4 files changed

+96
-68
lines changed

fibjs/include/ifs/console.h

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ class console_base : public object_base {
5858
static result_t crit(OptArgs args);
5959
static result_t alert(exlib::string fmt, OptArgs args);
6060
static result_t alert(OptArgs args);
61+
static result_t trace(exlib::string fmt, OptArgs args);
62+
static result_t trace(OptArgs args);
6163
static result_t dir(v8::Local<v8::Value> obj, v8::Local<v8::Object> options);
6264
static result_t table(v8::Local<v8::Value> obj);
6365
static result_t table(v8::Local<v8::Value> obj, v8::Local<v8::Array> fields);
6466
static result_t time(exlib::string label);
6567
static result_t timeElapse(exlib::string label);
6668
static result_t timeEnd(exlib::string label);
67-
static result_t trace(exlib::string label);
6869
static result_t _assert(v8::Local<v8::Value> value, exlib::string msg);
6970
static result_t print(exlib::string fmt, OptArgs args);
7071
static result_t print(OptArgs args);
@@ -99,12 +100,12 @@ class console_base : public object_base {
99100
static void s_static_error(const v8::FunctionCallbackInfo<v8::Value>& args);
100101
static void s_static_crit(const v8::FunctionCallbackInfo<v8::Value>& args);
101102
static void s_static_alert(const v8::FunctionCallbackInfo<v8::Value>& args);
103+
static void s_static_trace(const v8::FunctionCallbackInfo<v8::Value>& args);
102104
static void s_static_dir(const v8::FunctionCallbackInfo<v8::Value>& args);
103105
static void s_static_table(const v8::FunctionCallbackInfo<v8::Value>& args);
104106
static void s_static_time(const v8::FunctionCallbackInfo<v8::Value>& args);
105107
static void s_static_timeElapse(const v8::FunctionCallbackInfo<v8::Value>& args);
106108
static void s_static_timeEnd(const v8::FunctionCallbackInfo<v8::Value>& args);
107-
static void s_static_trace(const v8::FunctionCallbackInfo<v8::Value>& args);
108109
static void s_static__assert(const v8::FunctionCallbackInfo<v8::Value>& args);
109110
static void s_static_print(const v8::FunctionCallbackInfo<v8::Value>& args);
110111
static void s_static_moveTo(const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -134,12 +135,12 @@ inline ClassInfo& console_base::class_info()
134135
{ "error", s_static_error, true, false },
135136
{ "crit", s_static_crit, true, false },
136137
{ "alert", s_static_alert, true, false },
138+
{ "trace", s_static_trace, true, false },
137139
{ "dir", s_static_dir, true, false },
138140
{ "table", s_static_table, true, false },
139141
{ "time", s_static_time, true, false },
140142
{ "timeElapse", s_static_timeElapse, true, false },
141143
{ "timeEnd", s_static_timeEnd, true, false },
142-
{ "trace", s_static_trace, true, false },
143144
{ "assert", s_static__assert, true, false },
144145
{ "print", s_static_print, true, false },
145146
{ "moveTo", s_static_moveTo, true, false },
@@ -421,6 +422,26 @@ inline void console_base::s_static_alert(const v8::FunctionCallbackInfo<v8::Valu
421422
METHOD_VOID();
422423
}
423424

425+
inline void console_base::s_static_trace(const v8::FunctionCallbackInfo<v8::Value>& args)
426+
{
427+
METHOD_ENTER();
428+
429+
METHOD_OVER(-1, 1);
430+
431+
ARG(exlib::string, 0);
432+
ARG_LIST(1);
433+
434+
hr = trace(v0, v1);
435+
436+
METHOD_OVER(-1, 0);
437+
438+
ARG_LIST(0);
439+
440+
hr = trace(v0);
441+
442+
METHOD_VOID();
443+
}
444+
424445
inline void console_base::s_static_dir(const v8::FunctionCallbackInfo<v8::Value>& args)
425446
{
426447
METHOD_ENTER();
@@ -494,19 +515,6 @@ inline void console_base::s_static_timeEnd(const v8::FunctionCallbackInfo<v8::Va
494515
METHOD_VOID();
495516
}
496517

497-
inline void console_base::s_static_trace(const v8::FunctionCallbackInfo<v8::Value>& args)
498-
{
499-
METHOD_ENTER();
500-
501-
METHOD_OVER(1, 0);
502-
503-
OPT_ARG(exlib::string, 0, "trace");
504-
505-
hr = trace(v0);
506-
507-
METHOD_VOID();
508-
}
509-
510518
inline void console_base::s_static__assert(const v8::FunctionCallbackInfo<v8::Value>& args)
511519
{
512520
METHOD_ENTER();

fibjs/src/console/console.cpp

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,6 @@ void _log(int32_t type, exlib::string fmt, OptArgs args)
140140
}
141141
}
142142

143-
void _log(int32_t type, OptArgs args)
144-
{
145-
int32_t level;
146-
147-
console_base::get_loglevel(level);
148-
149-
if (type <= level) {
150-
exlib::string str;
151-
152-
util_format("", args, colors(type), str);
153-
asyncLog(type, str);
154-
}
155-
}
156-
157143
result_t console_base::log(exlib::string fmt, OptArgs args)
158144
{
159145
_log(C_INFO, fmt, args);
@@ -162,7 +148,7 @@ result_t console_base::log(exlib::string fmt, OptArgs args)
162148

163149
result_t console_base::log(OptArgs args)
164150
{
165-
_log(C_INFO, args);
151+
_log(C_INFO, "", args);
166152
return 0;
167153
}
168154

@@ -174,7 +160,7 @@ result_t console_base::debug(exlib::string fmt, OptArgs args)
174160

175161
result_t console_base::debug(OptArgs args)
176162
{
177-
_log(C_DEBUG, args);
163+
_log(C_DEBUG, "", args);
178164
return 0;
179165
}
180166

@@ -186,7 +172,7 @@ result_t console_base::info(exlib::string fmt, OptArgs args)
186172

187173
result_t console_base::info(OptArgs args)
188174
{
189-
_log(C_INFO, args);
175+
_log(C_INFO, "", args);
190176
return 0;
191177
}
192178

@@ -198,7 +184,7 @@ result_t console_base::notice(exlib::string fmt, OptArgs args)
198184

199185
result_t console_base::notice(OptArgs args)
200186
{
201-
_log(C_NOTICE, args);
187+
_log(C_NOTICE, "", args);
202188
return 0;
203189
}
204190

@@ -210,7 +196,7 @@ result_t console_base::warn(exlib::string fmt, OptArgs args)
210196

211197
result_t console_base::warn(OptArgs args)
212198
{
213-
_log(C_WARN, args);
199+
_log(C_WARN, "", args);
214200
return 0;
215201
}
216202

@@ -222,7 +208,7 @@ result_t console_base::error(exlib::string fmt, OptArgs args)
222208

223209
result_t console_base::error(OptArgs args)
224210
{
225-
_log(C_ERROR, args);
211+
_log(C_ERROR, "", args);
226212
return 0;
227213
}
228214

@@ -234,7 +220,7 @@ result_t console_base::crit(exlib::string fmt, OptArgs args)
234220

235221
result_t console_base::crit(OptArgs args)
236222
{
237-
_log(C_CRIT, args);
223+
_log(C_CRIT, "", args);
238224
return 0;
239225
}
240226

@@ -246,10 +232,39 @@ result_t console_base::alert(exlib::string fmt, OptArgs args)
246232

247233
result_t console_base::alert(OptArgs args)
248234
{
249-
_log(C_ALERT, args);
235+
_log(C_ALERT, "", args);
236+
return 0;
237+
}
238+
239+
result_t console_base::trace(exlib::string fmt, OptArgs args)
240+
{
241+
int32_t type = C_WARN;
242+
int32_t level;
243+
244+
console_base::get_loglevel(level);
245+
246+
if (type <= level) {
247+
exlib::string str;
248+
249+
util_format(fmt, args, colors(type), str);
250+
if (str.empty())
251+
str = "Trace";
252+
else
253+
str = "Trace: " + str;
254+
255+
str.append(1, '\n');
256+
str.append(traceInfo(Isolate::current()->m_isolate, 10));
257+
asyncLog(type, str);
258+
}
259+
250260
return 0;
251261
}
252262

263+
result_t console_base::trace(OptArgs args)
264+
{
265+
return trace("", args);
266+
}
267+
253268
result_t console_base::dir(v8::Local<v8::Value> obj, v8::Local<v8::Object> options)
254269
{
255270
exlib::string strBuffer;
@@ -318,19 +333,6 @@ result_t console_base::timeEnd(exlib::string label)
318333
return 0;
319334
}
320335

321-
result_t console_base::trace(exlib::string label)
322-
{
323-
exlib::string strBuffer;
324-
325-
strBuffer.append("console.trace: ", 15);
326-
strBuffer.append(label);
327-
strBuffer.append(1, '\n');
328-
strBuffer.append(traceInfo(Isolate::current()->m_isolate, 10));
329-
330-
asyncLog(C_WARN, strBuffer);
331-
return 0;
332-
}
333-
334336
result_t console_base::_assert(v8::Local<v8::Value> value, exlib::string msg)
335337
{
336338
return assert_base::ok(value, msg);
@@ -344,7 +346,7 @@ result_t console_base::print(exlib::string fmt, OptArgs args)
344346

345347
result_t console_base::print(OptArgs args)
346348
{
347-
_log(C_PRINT, args);
349+
_log(C_PRINT, "", args);
348350
return 0;
349351
}
350352

idl/zh-cn/console.idl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,21 @@ module console
257257
*/
258258
static alert(...args);
259259

260+
/*! @brief 输出当前调用堆栈
261+
262+
通过日志输出当前调用堆栈。
263+
@param fmt 格式化字符串
264+
@param args 可选参数列表
265+
*/
266+
static trace(String fmt, ...args);
267+
268+
/*! @brief 输出当前调用堆栈
269+
270+
通过日志输出当前调用堆栈。
271+
@param args 可选参数列表
272+
*/
273+
static trace(...args);
274+
260275
/*! @brief 用 JSON 格式输出对象
261276

262277
支持以下参数:
@@ -305,13 +320,6 @@ module console
305320
*/
306321
static timeEnd(String label = "time");
307322

308-
/*! @brief 输出当前调用堆栈
309-
310-
通过日志输出当前调用堆栈。
311-
@param label 标题,缺省为空字符串。
312-
*/
313-
static trace(String label = "trace");
314-
315323
/*! @brief 断言测试,如果测试值为假,则报错
316324
@param value 测试的数值
317325
@param msg 报错信息

npm/types/dts/module/console.d.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,25 @@ declare module 'console' {
325325
*/
326326
function alert(...args: any[]): void;
327327

328+
/**
329+
* @description 输出当前调用堆栈
330+
*
331+
* 通过日志输出当前调用堆栈。
332+
* @param fmt 格式化字符串
333+
* @param args 可选参数列表
334+
*
335+
*/
336+
function trace(fmt: string, ...args: any[]): void;
337+
338+
/**
339+
* @description 输出当前调用堆栈
340+
*
341+
* 通过日志输出当前调用堆栈。
342+
* @param args 可选参数列表
343+
*
344+
*/
345+
function trace(...args: any[]): void;
346+
328347
/**
329348
* @description 用 JSON 格式输出对象
330349
*
@@ -385,15 +404,6 @@ declare module 'console' {
385404
*/
386405
function timeEnd(label?: string): void;
387406

388-
/**
389-
* @description 输出当前调用堆栈
390-
*
391-
* 通过日志输出当前调用堆栈。
392-
* @param label 标题,缺省为空字符串。
393-
*
394-
*/
395-
function trace(label?: string): void;
396-
397407
/**
398408
* @description 断言测试,如果测试值为假,则报错
399409
* @param value 测试的数值

0 commit comments

Comments
 (0)
0