From 173b92fc8960d238374907780c26c110bf105140 Mon Sep 17 00:00:00 2001 From: Liu Date: Wed, 24 Jul 2019 22:14:22 +0800 Subject: [PATCH] feat(logger): support setting logging level --- include/LCUI/util/logger.h | 35 +++++++++-- include/LCUI_Build.h | 10 ++-- src/display.c | 16 ++--- src/font/fontlibrary.c | 38 ++++++------ src/font/textstyle.c | 1 - src/graph.c | 19 +++--- src/gui/builder.c | 28 +++++---- src/gui/css_library.c | 86 +++++++++++++-------------- src/gui/widget/anchor.c | 21 ++++--- src/gui/widget_tree.c | 10 ++-- src/image/jpeg.c | 6 +- src/image/png.c | 2 +- src/ime.c | 4 +- src/main.c | 51 ++++++++-------- src/platform/linux/linux_fbdisplay.c | 6 +- src/platform/linux/linux_keyboard.c | 6 +- src/platform/linux/linux_mouse.c | 6 +- src/platform/linux/linux_x11display.c | 6 +- src/util/dict.c | 86 +++++++++++++-------------- src/util/logger.c | 16 ++++- src/worker.c | 6 +- test/test.h | 38 ++++++------ 22 files changed, 270 insertions(+), 227 deletions(-) diff --git a/include/LCUI/util/logger.h b/include/LCUI/util/logger.h index 00c2babb6..937885115 100644 --- a/include/LCUI/util/logger.h +++ b/include/LCUI/util/logger.h @@ -33,13 +33,40 @@ LCUI_BEGIN_HEADER -LCUI_API int Logger_Log(const char* fmt, ...); +typedef enum LoggerLevel { + LOGGER_LEVEL_ALL, + LOGGER_LEVEL_DEBUG, + LOGGER_LEVEL_INFO, + LOGGER_LEVEL_WARNING, + LOGGER_LEVEL_ERROR, + LOGGER_LEVEL_OFF +} LoggerLevel; -LCUI_API int Logger_LogW(const wchar_t* fmt, ...); +LCUI_API void Logger_SetLevel(LoggerLevel level); -LCUI_API void Logger_SetHandler(void(*handler)(const char*)); +LCUI_API int Logger_Log(LoggerLevel level, const char* fmt, ...); -LCUI_API void Logger_SetHandlerW(void(*handler)(const wchar_t*)); +LCUI_API int Logger_LogW(LoggerLevel level, const wchar_t* fmt, ...); + +LCUI_API void Logger_SetHandler(void (*handler)(const char*)); + +LCUI_API void Logger_SetHandlerW(void (*handler)(const wchar_t*)); + +#define Logger_Info(fmt, ...) Logger_Log(LOGGER_LEVEL_INFO, fmt, ##__VA_ARGS__) +#define Logger_Debug(fmt, ...) \ + Logger_Log(LOGGER_LEVEL_DEBUG, fmt, ##__VA_ARGS__) +#define Logger_Warning(fmt, ...) \ + Logger_Log(LOGGER_LEVEL_WARNING, fmt, ##__VA_ARGS__) +#define Logger_Error(fmt, ...) \ + Logger_Log(LOGGER_LEVEL_ERROR, fmt, ##__VA_ARGS__) +#define Logger_InfoW(fmt, ...) \ + Logger_LogW(LOGGER_LEVEL_INFO, fmt, ##__VA_ARGS__) +#define Logger_DebugW(fmt, ...) \ + Logger_LogW(LOGGER_LEVEL_DEBUG, fmt, ##__VA_ARGS__) +#define Logger_WarningW(fmt, ...) \ + Logger_LogW(LOGGER_LEVEL_WARNING, fmt, ##__VA_ARGS__) +#define Logger_ErrorW(fmt, ...) \ + Logger_LogW(LOGGER_LEVEL_ERROR, fmt, ##__VA_ARGS__) LCUI_END_HEADER diff --git a/include/LCUI_Build.h b/include/LCUI_Build.h index 54b033036..d66deb0c7 100755 --- a/include/LCUI_Build.h +++ b/include/LCUI_Build.h @@ -52,11 +52,9 @@ #define DEBUG_MSG(format, ...) #endif -#define LOG Logger_Log -#define LOGW Logger_LogW -#define _DEBUG_MSG(format, ...) \ - Logger_Log(__FILE__ " %d: %s(): " format, __LINE__, __FUNCTION__, \ - ##__VA_ARGS__) +#define _DEBUG_MSG(format, ...) \ + Logger_Log(LOGGER_LEVEL_DEBUG, __FILE__ " %d: %s(): " format, \ + __LINE__, __FUNCTION__, ##__VA_ARGS__) #if defined(WIN32) || defined(_WIN32) #define LCUI_BUILD_IN_WIN32 @@ -69,7 +67,7 @@ #define ENABLE_TOUCH_SUPPORT #undef LCUI_THREAD_PTHREAD #undef LCUI_VIDEO_DRIVER_FRAMEBUFFER -#define PACKAGE_VERSION "1.1.0-beta" +#define PACKAGE_VERSION "1.3.0" #else #include #ifndef _GNU_SOURCE diff --git a/src/display.c b/src/display.c index 10e00b84a..108f6f2e4 100644 --- a/src/display.c +++ b/src/display.c @@ -625,8 +625,7 @@ static void OnSurfaceEvent(LCUI_Widget w, LCUI_WidgetEvent e, void *arg) case LCUI_WEVENT_HIDE: Surface_Hide(surface); break; - case LCUI_WEVENT_RESIZE: - { + case LCUI_WEVENT_RESIZE: { LCUI_Rect area; RectFToInvalidArea(rect, &area); if (sync_props) { @@ -671,8 +670,8 @@ static void OnResize(LCUI_Event e, void *arg) Widget_Resize(widget, width, height); } LCUI_RunFrame(); - LOG("[display] resize: (%d,%d)\n", dpy_ev->resize.width, - dpy_ev->resize.height); + Logger_Debug("[display] resize: (%d,%d)\n", dpy_ev->resize.width, + dpy_ev->resize.height); } static void OnMinMaxInfo(LCUI_Event e, void *arg) @@ -709,7 +708,7 @@ static void OnMinMaxInfo(LCUI_Event e, void *arg) } int LCUIDisplay_BindEvent(int event_id, LCUI_EventFunc func, void *arg, - void *data, void(*destroy_data)(void *)) + void *data, void (*destroy_data)(void *)) { if (display.active) { return display.driver->bindEvent(event_id, func, data, @@ -724,7 +723,7 @@ int LCUI_InitDisplay(LCUI_DisplayDriver driver) if (display.active) { return -1; } - LOG("[display] init ...\n"); + Logger_Info("[display] init ...\n"); display.mode = 0; display.driver = driver; display.active = TRUE; @@ -736,7 +735,7 @@ int LCUI_InitDisplay(LCUI_DisplayDriver driver) display.driver = LCUI_CreateDisplayDriver(); } if (!display.driver) { - LOG("[display] init failed\n"); + Logger_Warning("[display] init failed\n"); LCUIDisplay_SetMode(LCUI_DMODE_DEFAULT); LCUIDisplay_Update(); return -2; @@ -749,7 +748,8 @@ int LCUI_InitDisplay(LCUI_DisplayDriver driver) Widget_BindEvent(root, "surface", OnSurfaceEvent, NULL, NULL); LCUIDisplay_SetMode(LCUI_DMODE_DEFAULT); LCUIDisplay_Update(); - LOG("[display] init ok, driver name: %s\n", display.driver->name); + Logger_Info("[display] init ok, driver name: %s\n", + display.driver->name); return 0; } diff --git a/src/font/fontlibrary.c b/src/font/fontlibrary.c index 018397b76..5cb55d7e3 100644 --- a/src/font/fontlibrary.c +++ b/src/font/fontlibrary.c @@ -90,7 +90,8 @@ static struct LCUI_FontLibraryModule { /* clang-format on */ -#define FontBitmap_IsValid(fbmp) ((fbmp) && (fbmp)->width > 0 && (fbmp)->rows > 0) +#define FontBitmap_IsValid(fbmp) \ + ((fbmp) && (fbmp)->width > 0 && (fbmp)->rows > 0) #define SelectChar(ch) (RBTree *)RBTree_GetData(&fontlib.bitmap_cache, ch) #define SelectFont(ch, font_id) (RBTree *)RBTree_GetData(ch, font_id) #define SelectBitmap(font, size) (LCUI_FontBitmap *)RBTree_GetData(font, size) @@ -145,7 +146,7 @@ static int SetFontCache(LCUI_Font font) LCUI_FontCache *caches, cache; if (font->id > FONT_CACHE_MAX_SIZE) { - LOG("[font] font cache size is the max size\n"); + Logger_Error("[font] font cache size is the max size\n"); return -1; } while (font->id >= fontlib.font_cache_num * FONT_CACHE_SIZE) { @@ -310,7 +311,8 @@ size_t LCUIFont_UpdateWeight(const int *font_ids, LCUI_FontWeight weight, if (!font_ids) { return 0; } - for (len = 0; font_ids[len]; ++len); + for (len = 0; font_ids[len]; ++len) + ; if (len < 1) { return 0; } @@ -515,7 +517,7 @@ void LCUIFont_SetDefault(int id) LCUI_Font font = LCUIFont_GetById(id); if (font) { fontlib.default_font = font; - LOG("[font] select: %s\n", font->family_name); + Logger_Info("[font] select: %s\n", font->family_name); } } @@ -621,20 +623,20 @@ static int LCUIFont_LoadFileEx(LCUI_FontEngine *engine, const char *file) LCUI_Font *fonts; int i, num_fonts, id; - LOG("[font] load file: %s\n", file); + Logger_Debug("[font] load file: %s\n", file); if (!engine) { return -1; } num_fonts = fontlib.engine->open(file, &fonts); if (num_fonts < 1) { - LOG("[font] failed to load file: %s\n", file); + Logger_Debug("[font] failed to load file: %s\n", file); return -2; } for (i = 0; i < num_fonts; ++i) { fonts[i]->engine = engine; id = LCUIFont_Add(fonts[i]); - LOG("[font] add family: %s, style name: %s, id: %d\n", - fonts[i]->family_name, fonts[i]->style_name, id); + Logger_Info("[font] add family: %s, style name: %s, id: %d\n", + fonts[i]->family_name, fonts[i]->style_name, id); } free(fonts); return 0; @@ -648,11 +650,11 @@ int LCUIFont_LoadFile(const char *filepath) /** 打印字体位图的信息 */ void FontBitmap_PrintInfo(LCUI_FontBitmap *bitmap) { - LOG("address:%p\n", bitmap); + printf("address:%p\n", bitmap); if (!bitmap) { return; } - LOG("top: %d, left: %d, width:%d, rows:%d\n", bitmap->top, bitmap->left, + printf("top: %d, left: %d, width:%d, rows:%d\n", bitmap->top, bitmap->left, bitmap->width, bitmap->rows); } @@ -704,16 +706,16 @@ int FontBitmap_Print(LCUI_FontBitmap *fontbmp) m = y * fontbmp->width; for (x = 0; x < fontbmp->width; ++x, ++m) { if (fontbmp->buffer[m] > 128) { - LOG("#"); + printf("#"); } else if (fontbmp->buffer[m] > 64) { - LOG("-"); + printf("-"); } else { - LOG(" "); + printf(" "); } } - LOG("\n"); + printf("\n"); } - LOG("\n"); + printf("\n"); return 0; } @@ -857,10 +859,10 @@ static void LCUIFont_InitEngine(void) } #endif if (fontlib.engine && fontlib.engine != &fontlib.engines[0]) { - LOG("[font] current font engine is: %s\n", + Logger_Info("[font] current font engine is: %s\n", fontlib.engine->name); } else { - LOG("[font] warning: not font engine support!\n"); + Logger_Warning("[font] warning: not font engine support!\n"); } } @@ -976,7 +978,7 @@ static void LCUIFont_LoadDefaultFonts(void) #ifdef LCUI_BUILD_IN_WIN32 LCUIFont_LoadFontsForWindows(); #elif defined(USE_FONTCONFIG) - LOG("[font] fontconfig enabled\n"); + Logger_Info("[font] fontconfig enabled\n"); LCUIFont_LoadFontsByFontConfig(); #else LCUIFont_LoadFontsForLinux(); diff --git a/src/font/textstyle.c b/src/font/textstyle.c index b89b83959..05f0c17ea 100755 --- a/src/font/textstyle.c +++ b/src/font/textstyle.c @@ -314,7 +314,6 @@ const wchar_t *ScanStyleEndingTag(const wchar_t *wstr, wchar_t *name) size_t i, j, len; len = wcslen(wstr); - //LOG("string: %S\n", wstr); if (wstr[0] != '[' || wstr[1] != '/') { return NULL; } diff --git a/src/graph.c b/src/graph.c index dbfaeb7f9..c9da235f6 100644 --- a/src/graph.c +++ b/src/graph.c @@ -39,17 +39,18 @@ void Graph_PrintInfo(LCUI_Graph *graph) { - LOG("address:%p\n", graph); + printf("address:%p\n", graph); if (!graph) { return; } - LOG("width:%d, ", graph->width); - LOG("height:%d, ", graph->height); - LOG("opacity:%.2f, ", graph->opacity); - LOG("%s\n", graph->color_type == LCUI_COLOR_TYPE_ARGB ? "RGBA" : "RGB"); + printf("width:%d, ", graph->width); + printf("height:%d, ", graph->height); + printf("opacity:%.2f, ", graph->opacity); + printf("%s\n", + graph->color_type == LCUI_COLOR_TYPE_ARGB ? "RGBA" : "RGB"); if (graph->quote.is_valid) { - LOG("graph src:"); + printf("graph src:"); Graph_PrintInfo(Graph_GetQuote(graph)); } } @@ -701,7 +702,7 @@ static uchar_t Graph_BilinearResamplingCore(uchar_t a, uchar_t b, uchar_t c, uchar_t d, float dx, float dy) { return (uchar_t)(a * (1 - dx) * (1 - dy) + b * (dx) * (1 - dy) + - c * (dy) * (1 - dx) + d * (dx * dy)); + c * (dy) * (1 - dx) + d * (dx * dy)); } /*-------------------------------- End ARGB --------------------------------*/ @@ -1043,8 +1044,8 @@ int Graph_ZoomBilinear(const LCUI_Graph *graph, LCUI_Graph *buff, if (graph->color_type != LCUI_COLOR_TYPE_RGB && graph->color_type != LCUI_COLOR_TYPE_ARGB) { /* fall back to nearest scaling */ - LOG("[graph] unable to perform bilinear scaling, " - "fallback...\n"); + Logger_Debug("[graph] unable to perform bilinear scaling, " + "fallback...\n"); return Graph_Zoom(graph, buff, keep_scale, width, height); } if (!Graph_IsValid(graph) || (width <= 0 && height <= 0)) { diff --git a/src/gui/builder.c b/src/gui/builder.c index 96fee9b2c..0c633e34b 100644 --- a/src/gui/builder.c +++ b/src/gui/builder.c @@ -272,20 +272,23 @@ static void ParseNode(XMLParserContext ctx, xmlNodePtr node) if (node->type == XML_ELEMENT_NODE) { p = RBTree_CustomGetData(&self.parsers, node->name); if (!p) { - proto = LCUIWidget_GetPrototype(node->name); + proto = + LCUIWidget_GetPrototype((char *)node->name); /* If there is no suitable parser, but a widget * prototype with the same name already exists, * use the widget parser */ if (proto) { p = &parser_list[1]; + } else { + continue; } } } else { p = ctx->parent_parser; - } - if (!p) { - continue; + if (!p) { + continue; + } } cur_ctx = *ctx; cur_ctx.parent_widget = ctx->widget; @@ -298,12 +301,12 @@ static void ParseNode(XMLParserContext ctx, xmlNodePtr node) case PB_NEXT: break; case PB_WARNING: - LOG("[builder] %s (%d): warning: %s node.\n", + Logger_Warning("[builder] %s (%d): warning: %s node.\n", node->doc->name, node->line, node->name); break; case PB_ERROR: default: - LOG("[builder] %s (%d): error: %s node.\n", + Logger_Error("[builder] %s (%d): error: %s node.\n", node->doc->name, node->line, node->name); break; } @@ -317,7 +320,7 @@ static void ParseNode(XMLParserContext ctx, xmlNodePtr node) LCUI_Widget LCUIBuilder_LoadString(const char *str, int size) { #ifndef USE_LCUI_BUILDER - LOG(WARN_TXT); + Logger_Warning(WARN_TXT); #else xmlDocPtr doc; xmlNodePtr cur; @@ -326,12 +329,12 @@ LCUI_Widget LCUIBuilder_LoadString(const char *str, int size) memset(&ctx, 0, sizeof(ctx)); doc = xmlParseMemory(str, size); if (!doc) { - LOG("[builder] Failed to parse xml form memory\n"); + Logger_Error("[builder] Failed to parse xml form memory\n"); goto FAILED; } cur = xmlDocGetRootElement(doc); if (xmlStrcasecmp(cur->name, BAD_CAST "lcui-app")) { - LOG("[builder] error root node name: %s\n", cur->name); + Logger_Error("[builder] error root node name: %s\n", cur->name); goto FAILED; } if (!self.active) { @@ -350,7 +353,7 @@ LCUI_Widget LCUIBuilder_LoadString(const char *str, int size) LCUI_Widget LCUIBuilder_LoadFile(const char *filepath) { #ifndef USE_LCUI_BUILDER - LOG(WARN_TXT); + Logger_Warning(WARN_TXT); #else xmlDocPtr doc; xmlNodePtr cur; @@ -360,12 +363,13 @@ LCUI_Widget LCUIBuilder_LoadFile(const char *filepath) ctx.space = filepath; doc = xmlParseFile(filepath); if (!doc) { - LOG("[builder] Failed to parse xml file: %s\n", filepath); + Logger_Error("[builder] Failed to parse xml file: %s\n", + filepath); goto FAILED; } cur = xmlDocGetRootElement(doc); if (xmlStrcasecmp(cur->name, BAD_CAST "lcui-app")) { - LOG("[builder] error root node name: %s\n", cur->name); + Logger_Error("[builder] error root node name: %s\n", cur->name); goto FAILED; } if (!self.active) { diff --git a/src/gui/css_library.c b/src/gui/css_library.c index 7de57287c..2a34952e2 100644 --- a/src/gui/css_library.c +++ b/src/gui/css_library.c @@ -971,10 +971,9 @@ int Selector_AppendNode(LCUI_Selector selector, LCUI_SelectorNode node) const unsigned char *p; if (selector->length >= MAX_SELECTOR_DEPTH) { - LOG("[css] warning: the number of nodes in the selector has " - "exceeded " - "the %d limit\n", - MAX_SELECTOR_DEPTH); + Logger_Warning("[css] warning: the number of nodes in the " + "selector has exceeded the %d limit\n", + MAX_SELECTOR_DEPTH); return -1; } selector->nodes[selector->length++] = node; @@ -1007,7 +1006,7 @@ LCUI_Selector Selector(const char *selector) if (!node && is_saving) { node = NEW(LCUI_SelectorNodeRec, 1); if (si >= MAX_SELECTOR_DEPTH) { - _DEBUG_MSG( + Logger_Warning( "%s: selector node list is too long.\n", selector); return NULL; @@ -1032,8 +1031,8 @@ LCUI_Selector Selector(const char *selector) ni = 0; continue; } - _DEBUG_MSG("%s: invalid selector node at %ld.\n", - selector, p - selector - ni); + Logger_Error("%s: invalid selector node at %ld.\n", + selector, p - selector - ni); SelectorNode_Delete(node); node = NULL; ni = 0; @@ -1057,8 +1056,8 @@ LCUI_Selector Selector(const char *selector) si++; continue; } - _DEBUG_MSG("%s: invalid selector node at %ld.\n", - selector, p - selector - ni); + Logger_Error("%s: invalid selector node at %ld.\n", + selector, p - selector - ni); SelectorNode_Delete(node); node = NULL; ni = 0; @@ -1077,15 +1076,15 @@ LCUI_Selector Selector(const char *selector) name[ni] = 0; continue; } - _DEBUG_MSG("%s: unknown char 0x%02x at %ld.\n", selector, *p, - p - selector); + Logger_Warning("%s: unknown char 0x%02x at %ld.\n", + selector, *p, p - selector); return NULL; } if (is_saving) { if (!node) { node = NEW(LCUI_SelectorNodeRec, 1); if (si >= MAX_SELECTOR_DEPTH) { - _DEBUG_MSG( + Logger_Warning( "%s: selector node list is too long.\n", selector); return NULL; @@ -1404,61 +1403,61 @@ static void PrintStyleName(int key) name = LCUI_GetStyleName(key); if (name) { - LOG("\t%s", name); + Logger_Debug("\t%s", name); } else { - LOG("\t", key); + Logger_Debug("\t", key); } - LOG("%s: ", key > STYLE_KEY_TOTAL ? " (+)" : ""); + Logger_Debug("%s: ", key > STYLE_KEY_TOTAL ? " (+)" : ""); } static void PrintStyleValue(LCUI_Style s) { switch (s->type) { case LCUI_STYPE_AUTO: - LOG("auto"); + Logger_Debug("auto"); break; case LCUI_STYPE_BOOL: - LOG("%s", s->val_bool ? "true" : "false"); + Logger_Debug("%s", s->val_bool ? "true" : "false"); break; case LCUI_STYPE_COLOR: { LCUI_Color *clr = &s->val_color; if (clr->alpha < 255) { - LOG("rgba(%d,%d,%d,%g)", clr->r, clr->g, clr->b, + Logger_Debug("rgba(%d,%d,%d,%g)", clr->r, clr->g, clr->b, clr->a / 255.0); } else { - LOG("#%02x%02x%02x", clr->r, clr->g, clr->b); + Logger_Debug("#%02x%02x%02x", clr->r, clr->g, clr->b); } break; } case LCUI_STYPE_PX: - LOG("%gpx", s->val_px); + Logger_Debug("%gpx", s->val_px); break; case LCUI_STYPE_DIP: - LOG("%gdip", s->val_dip); + Logger_Debug("%gdip", s->val_dip); break; case LCUI_STYPE_SP: - LOG("%gsp", s->val_sp); + Logger_Debug("%gsp", s->val_sp); break; case LCUI_STYPE_STRING: - LOG("%s", s->val_string); + Logger_Debug("%s", s->val_string); break; case LCUI_STYPE_WSTRING: - LOG("%S", s->val_wstring); + Logger_Debug("%S", s->val_wstring); break; case LCUI_STYPE_SCALE: - LOG("%g%%", s->val_scale * 100); + Logger_Debug("%g%%", s->val_scale * 100); break; case LCUI_STYPE_STYLE: - LOG("%s", LCUI_GetStyleValueName(s->val_style)); + Logger_Debug("%s", LCUI_GetStyleValueName(s->val_style)); break; case LCUI_STYPE_INT: - LOG("%d", s->val_int); + Logger_Debug("%d", s->val_int); break; default: - LOG("%g", s->value); + Logger_Debug("%g", s->value); break; } - LOG(";\n"); + Logger_Debug(";\n"); } void LCUI_PrintStyleList(LCUI_StyleList list) @@ -1499,8 +1498,8 @@ void LCUI_PrintSelector(LCUI_Selector selector) strcat(path, (*sn)->fullname); strcat(path, " "); } - LOG("path: %s (rank = %d, batch_num = %d)\n", path, selector->rank, - selector->batch_num); + Logger_Debug("path: %s (rank = %d, batch_num = %d)\n", path, + selector->rank, selector->batch_num); } static void LCUI_PrintStyleLink(StyleLink link, const char *selector) @@ -1509,6 +1508,7 @@ static void LCUI_PrintStyleLink(StyleLink link, const char *selector) DictIterator *iter; LinkedListNode *node; char fullname[MAX_SELECTOR_LEN]; + if (selector) { sprintf(fullname, "%s %s", link->group->name, selector); } else { @@ -1516,10 +1516,10 @@ static void LCUI_PrintStyleLink(StyleLink link, const char *selector) } for (LinkedList_Each(node, &link->styles)) { StyleNode snode = node->data; - LOG("\n[%s]", snode->space ? snode->space : ""); - LOG("[rank: %d]\n%s {\n", snode->rank, fullname); + Logger_Debug("\n[%s]", snode->space ? snode->space : ""); + Logger_Debug("[rank: %d]\n%s {\n", snode->rank, fullname); LCUI_PrintStyleList(snode->list); - LOG("}\n"); + Logger_Debug("}\n"); } iter = Dict_GetIterator(link->parents); while ((entry = Dict_Next(iter))) { @@ -1538,7 +1538,7 @@ void LCUI_PrintCSSLibrary(void) DictEntry *entry; link = NULL; - LOG("style library begin\n"); + Logger_Debug("style library begin\n"); group = LinkedList_Get(&library.groups, 0); iter = Dict_GetIterator(group); while ((entry = Dict_Next(iter))) { @@ -1554,7 +1554,7 @@ void LCUI_PrintCSSLibrary(void) Dict_ReleaseIterator(iter_slg); } Dict_ReleaseIterator(iter); - LOG("style library end\n"); + Logger_Debug("style library end\n"); } LCUI_CachedStyleSheet LCUI_GetCachedStyleSheet(LCUI_Selector s) @@ -1596,21 +1596,21 @@ void LCUI_PrintStyleSheetsBySelector(LCUI_Selector s) LinkedList_Init(&list); ss = StyleSheet(); LCUI_FindStyleSheet(s, &list); - LOG("selector(%u) stylesheets begin\n", s->hash); + Logger_Debug("selector(%u) stylesheets begin\n", s->hash); for (LinkedList_Each(node, &list)) { StyleNode sn = node->data; - LOG("\n[%s]", sn->space ? sn->space : ""); - LOG("[rank: %d]\n%s {\n", sn->rank, sn->selector); + Logger_Debug("\n[%s]", sn->space ? sn->space : ""); + Logger_Debug("[rank: %d]\n%s {\n", sn->rank, sn->selector); LCUI_PrintStyleList(sn->list); - LOG("}\n"); + Logger_Debug("}\n"); StyleSheet_MergeList(ss, sn->list); } LinkedList_Clear(&list, NULL); - LOG("[selector(%u) final stylesheet] {\n", s->hash); + Logger_Debug("[selector(%u) final stylesheet] {\n", s->hash); LCUI_PrintStyleSheet(ss); - LOG("}\n"); + Logger_Debug("}\n"); StyleSheet_Delete(ss); - LOG("selector(%u) stylesheets end\n", s->hash); + Logger_Debug("selector(%u) stylesheets end\n", s->hash); } static void StyleSheetCacheDestructor(void *privdata, void *val) diff --git a/src/gui/widget/anchor.c b/src/gui/widget/anchor.c index bcca9046a..22435bb96 100644 --- a/src/gui/widget/anchor.c +++ b/src/gui/widget/anchor.c @@ -51,8 +51,7 @@ static struct LCUI_Anchor { LCUI_WidgetPrototype proto; } self; -static void Loader_OnClearWidget(LCUI_Widget w, - LCUI_WidgetEvent e, void *arg) +static void Loader_OnClearWidget(LCUI_Widget w, LCUI_WidgetEvent e, void *arg) { LCUI_XMLLoader loader = e->data; loader->widget = NULL; @@ -121,10 +120,9 @@ static void XMLLoader_Load(LCUI_XMLLoader loader) char *path, dirname[] = "assets/views/"; if (loader->filepath[0] != '/') { - path = malloc(strsize(loader->filepath) + - sizeof(dirname)); + path = malloc(strsize(loader->filepath) + sizeof(dirname)); if (!path) { - LOG("[anchor] out of memory\n"); + Logger_Error("[anchor] out of memory\n"); return; } strcpy(path, dirname); @@ -133,8 +131,8 @@ static void XMLLoader_Load(LCUI_XMLLoader loader) free(path); if (pack) { loader->pack = pack; - LCUI_PostSimpleTask(XMLLoader_AppendToTarget, - loader, NULL); + LCUI_PostSimpleTask(XMLLoader_AppendToTarget, loader, + NULL); return; } } @@ -144,7 +142,7 @@ static void XMLLoader_Load(LCUI_XMLLoader loader) LCUI_PostSimpleTask(XMLLoader_AppendToTarget, loader, NULL); return; } - LOG("[anchor] href (%s): cannot load xml resource\n", + Logger_Error("[anchor] href (%s): cannot load xml resource\n", loader->filepath); XMLLoader_Destroy(loader); } @@ -155,7 +153,8 @@ static void XMLLoader_StartLoad(LCUI_XMLLoader loader) LCUI_TaskRec task = { 0 }; target = LCUIWidget_GetById(loader->target_id); if (!target) { - LOG("[anchor] target (%s): not found\n", loader->target_id); + Logger_Error("[anchor] target (%s): not found\n", + loader->target_id); return; } Widget_Empty(target); @@ -170,7 +169,7 @@ void Anchor_Open(LCUI_Widget w) const char *attr_href = Widget_GetAttribute(w, "href"); if (!attr_href) { - LOG("[anchor] href are required\n"); + Logger_Error("[anchor] href are required\n"); return; } if (strstr(attr_href, "file:") == attr_href) { @@ -184,7 +183,7 @@ void Anchor_Open(LCUI_Widget w) } loader = XMLLoader_New(w); if (!loader) { - LOG("[anchor] out of memory\n"); + Logger_Error("[anchor] out of memory\n"); return; } LCUI_PostSimpleTask(XMLLoader_StartLoad, loader, NULL); diff --git a/src/gui/widget_tree.c b/src/gui/widget_tree.c index 6e56e7370..28474e4c8 100644 --- a/src/gui/widget_tree.c +++ b/src/gui/widget_tree.c @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -253,7 +254,8 @@ static void _LCUIWidget_PrintTree(LCUI_Widget w, int depth, const char *prefix) strcat(str, "┬"); } snode = Widget_GetSelectorNode(child); - LOG("%s%s %s, xy:(%g,%g), size:(%g,%g), " + Logger_Debug( + "%s%s %s, xy:(%g,%g), size:(%g,%g), " "visible: %s, display: %d, padding: (%g,%g,%g,%g), margin: " "(%g,%g,%g,%g)\n", prefix, str, snode->fullname, child->x, child->y, @@ -273,9 +275,9 @@ void Widget_PrintTree(LCUI_Widget w) LCUI_SelectorNode node; w = w ? w : LCUIWidget_GetRoot(); node = Widget_GetSelectorNode(w); - LOG("%s, xy:(%g,%g), size:(%g,%g), visible: %s\n", node->fullname, w->x, - w->y, w->width, w->height, - w->computed_style.visible ? "true" : "false"); + Logger_Debug("%s, xy:(%g,%g), size:(%g,%g), visible: %s\n", + node->fullname, w->x, w->y, w->width, w->height, + w->computed_style.visible ? "true" : "false"); SelectorNode_Delete(node); _LCUIWidget_PrintTree(w, 0, " "); } diff --git a/src/image/jpeg.c b/src/image/jpeg.c index ccdda5e57..b5dbeee0c 100644 --- a/src/image/jpeg.c +++ b/src/image/jpeg.c @@ -72,7 +72,7 @@ METHODDEF(void) JPEGReader_OnErrorExit(j_common_ptr cinfo) char msg[JMSG_LENGTH_MAX]; LCUI_JPEGError err = (LCUI_JPEGError)cinfo->err; cinfo->err->format_message(cinfo, msg); - LOG("%s\n", msg); + Logger_Error("%s\n", msg); longjmp(*err->reader->env, 1); } @@ -229,7 +229,7 @@ int LCUI_InitJPEGReader(LCUI_ImageReader reader) jpeg_reader->err.reader = reader; return 0; #else - LOG("warning: not JPEG support!"); + Logger_Warning("warning: not JPEG support!"); #endif return -1; } @@ -283,7 +283,7 @@ int LCUI_ReadJPEG(LCUI_ImageReader reader, LCUI_Graph *graph) } return 0; #else - LOG("warning: not JPEG support!"); + Logger_Warning("warning: not JPEG support!"); #endif return -ENOSYS; } diff --git a/src/image/png.c b/src/image/png.c index 450e04f8f..fd796fbcc 100644 --- a/src/image/png.c +++ b/src/image/png.c @@ -333,7 +333,7 @@ int LCUI_WritePNGFile(const char *file_name, const LCUI_Graph *graph) fclose(fp); return 0; #else - LOG("warning: not PNG support!"); + Logger_Warning("warning: not PNG support!"); return -ENOSYS; #endif } diff --git a/src/ime.c b/src/ime.c index 2c094aadc..59506b87a 100644 --- a/src/ime.c +++ b/src/ime.c @@ -120,7 +120,7 @@ static LCUI_BOOL LCUIIME_Open(LCUI_IME ime) static LCUI_BOOL LCUIIME_Close(LCUI_IME ime) { if (ime && ime->handler.close) { - LOG("[ime] close engine: %s\n", ime->name); + Logger_Info("[ime] close engine: %s\n", ime->name); return ime->handler.close(); } return FALSE; @@ -131,7 +131,7 @@ LCUI_BOOL LCUIIME_Select(int ime_id) LCUI_IME ime = LCUIIME_Find(ime_id); if (ime) { LCUIIME_Close(self.ime); - LOG("[ime] select engine: %s\n", ime->name); + Logger_Info("[ime] select engine: %s\n", ime->name); self.ime = ime; LCUIIME_Open(self.ime); return TRUE; diff --git a/src/main.c b/src/main.c index a06c7f22a..be7d12c06 100644 --- a/src/main.c +++ b/src/main.c @@ -123,30 +123,32 @@ static void LCUIProfile_Print(LCUI_Profile profile) unsigned i; LCUI_FrameProfile frame; - LOG("\nframes_count: %zu, time: %ld\n", profile->frames_count, - profile->end_time - profile->start_time); + Logger_Debug("\nframes_count: %zu, time: %ld\n", profile->frames_count, + profile->end_time - profile->start_time); for (i = 0; i < profile->frames_count; ++i) { frame = &profile->frames[i]; - LOG("=== frame [%u/%u] ===\n", i + 1, profile->frames_count); - LOG("timers.count: %zu\ntimers.time: %ldms\n", - frame->timers_count, frame->timers_time); - LOG("events.count: %zu\nevents.time: %ldms\n", - frame->events_count, frame->events_time); - LOG("widget_tasks.time: %ldms\n" - "widget_tasks.update_count: %u\n" - "widget_tasks.refresh_count: %u\n" - "widget_tasks.layout_count: %u\n" - "widget_tasks.user_task_count: %u\n" - "widget_tasks.destroy_count: %u\n" - "widget_tasks.destroy_time: %ldms\n", - frame->widget_tasks.time, frame->widget_tasks.update_count, - frame->widget_tasks.refresh_count, - frame->widget_tasks.layout_count, - frame->widget_tasks.user_task_count, - frame->widget_tasks.destroy_count, - frame->widget_tasks.destroy_time); - LOG("render: %zu, %ldms, %ldms\n", frame->render_count, - frame->render_time, frame->present_time); + Logger_Debug("=== frame [%u/%u] ===\n", i + 1, + profile->frames_count); + Logger_Debug("timers.count: %zu\ntimers.time: %ldms\n", + frame->timers_count, frame->timers_time); + Logger_Debug("events.count: %zu\nevents.time: %ldms\n", + frame->events_count, frame->events_time); + Logger_Debug("widget_tasks.time: %ldms\n" + "widget_tasks.update_count: %u\n" + "widget_tasks.refresh_count: %u\n" + "widget_tasks.layout_count: %u\n" + "widget_tasks.user_task_count: %u\n" + "widget_tasks.destroy_count: %u\n" + "widget_tasks.destroy_time: %ldms\n", + frame->widget_tasks.time, + frame->widget_tasks.update_count, + frame->widget_tasks.refresh_count, + frame->widget_tasks.layout_count, + frame->widget_tasks.user_task_count, + frame->widget_tasks.destroy_count, + frame->widget_tasks.destroy_time); + Logger_Debug("render: %zu, %ldms, %ldms\n", frame->render_count, + frame->render_time, frame->present_time); } } @@ -560,7 +562,8 @@ static void LCUIApp_QuitAllMainLoop(void) static void LCUI_ShowCopyrightText(void) { - Logger_Log("LCUI (LC's UI) version " PACKAGE_VERSION "\n" + Logger_Log(LOGGER_LEVEL_INFO, + "LCUI (LC's UI) version " PACKAGE_VERSION "\n" #ifdef _MSC_VER "Build tool: " #if (_MSC_VER > 1912) @@ -583,7 +586,7 @@ static void LCUI_ShowCopyrightText(void) "Build at "__DATE__ " - "__TIME__ "\n" - "Copyright (C) 2012-2018 Liu Chao .\n" + "Copyright (C) 2012-2019 Liu Chao .\n" "This is open source software, licensed under MIT. \n" "See source distribution for detailed copyright notices.\n" "To learn more, visit http://www.lcui.org.\n\n"); diff --git a/src/platform/linux/linux_fbdisplay.c b/src/platform/linux/linux_fbdisplay.c index 0abac7e17..1b16f7840 100644 --- a/src/platform/linux/linux_fbdisplay.c +++ b/src/platform/linux/linux_fbdisplay.c @@ -478,10 +478,10 @@ static int FBDisplay_Init(void) if (!display.fb.dev_path) { display.fb.dev_path = "/dev/fb0"; } - LOG("[display] open framebuffer device: %s\n", display.fb.dev_path); + Logger_Debug("[display] open framebuffer device: %s\n", display.fb.dev_path); display.fb.dev_fd = open(display.fb.dev_path, O_RDWR); if (display.fb.dev_fd == -1) { - perror("[display] open framebuffer device failed"); + Logger_Error("[display] open framebuffer device failed"); return -1; } ioctl(display.fb.dev_fd, FBIOGET_VSCREENINFO, &display.fb.var_info); @@ -492,7 +492,7 @@ static int FBDisplay_Init(void) display.fb.mem = mmap(NULL, display.fb.mem_len, PROT_READ | PROT_WRITE, MAP_SHARED, display.fb.dev_fd, 0); if ((void *)-1 == display.fb.mem) { - perror("[display] framebuffer mmap failed"); + Logger_Error("[display] framebuffer mmap failed"); return -1; } FBDisplay_PrintInfo(); diff --git a/src/platform/linux/linux_keyboard.c b/src/platform/linux/linux_keyboard.c index 44a0693f5..c36f6ab4a 100644 --- a/src/platform/linux/linux_keyboard.c +++ b/src/platform/linux/linux_keyboard.c @@ -69,7 +69,7 @@ static void LinuxKeybnoardThread(void *arg) struct input_event data; keyboard.active = TRUE; - LOG("[input] keyboard driver thread: %lld\n", keyboard.tid); + Logger_Debug("[input] keyboard driver thread: %lld\n", keyboard.tid); while (keyboard.active) { bytes = read(keyboard.dev_fd, &data, sizeof(data)); if (bytes > 0 && data.type == EV_KEY) { @@ -87,7 +87,7 @@ static int InitLinuxKeybord(void) } if ((keyboard.dev_fd = open(keyboard.dev_path, O_RDONLY | O_NONBLOCK)) < 0) { - perror("[input] open keyboard device failed"); + Logger_Error("[input] open keyboard device failed"); return -1; } LCUIThread_Create(&keyboard.tid, LinuxKeybnoardThread, NULL); @@ -248,7 +248,7 @@ static int InitLinuxKeybord(void) signal(signals[i], on_signal); } LCUIThread_Create(&keyboard.tid, LinuxKeybnoardThread, NULL); - LOG("[input] keyboard driver thread: %lld\n", keyboard.tid); + Logger_Debug("[input] keyboard driver thread: %lld\n", keyboard.tid); return 0; } diff --git a/src/platform/linux/linux_mouse.c b/src/platform/linux/linux_mouse.c index 78693c965..be41f1cc0 100644 --- a/src/platform/linux/linux_mouse.c +++ b/src/platform/linux/linux_mouse.c @@ -148,13 +148,13 @@ static int InitLinuxMouse(void) if (!mouse.dev_path) { mouse.dev_path = "/dev/input/mice"; } - LOG("[input] open mouse device: %s\n", mouse.dev_path); + Logger_Debug("[input] open mouse device: %s\n", mouse.dev_path); if ((mouse.dev_fd = open(mouse.dev_path, O_RDONLY)) < 0) { - perror("[input] open mouse device failed"); + Logger_Error("[input] open mouse device failed"); return -1; } LCUIThread_Create(&mouse.tid, LinuxMouseThread, NULL); - LOG("[input] mouse driver thread: %lld\n", mouse.tid); + Logger_Debug("[input] mouse driver thread: %lld\n", mouse.tid); return 0; } diff --git a/src/platform/linux/linux_x11display.c b/src/platform/linux/linux_x11display.c index 29ce08789..6d22b45cb 100644 --- a/src/platform/linux/linux_x11display.c +++ b/src/platform/linux/linux_x11display.c @@ -145,7 +145,7 @@ static void X11Surface_OnResize(LCUI_Surface s, int width, int height) s->fb.color_type = LCUI_COLOR_TYPE_ARGB; break; default: - LOG("[x11display] unsupport depth: %d.\n", depth); + Logger_Error("[x11display] unsupport depth: %d.\n", depth); break; } Graph_Create(&s->fb, width, height); @@ -154,14 +154,14 @@ static void X11Surface_OnResize(LCUI_Surface s, int width, int height) (char *)(s->fb.bytes), width, height, 32, 0); if (!s->ximage) { Graph_Free(&s->fb); - LOG("[x11display] create XImage faild.\n"); + Logger_Error("[x11display] create XImage faild.\n"); return; } gcv.graphics_exposures = False; s->gc = XCreateGC(x11.app->display, s->window, GCGraphicsExposures, &gcv); if (!s->gc) { - LOG("[x11display] create graphics context faild.\n"); + Logger_Error("[x11display] create graphics context faild.\n"); return; } } diff --git a/src/util/dict.c b/src/util/dict.c index a5d239104..7d8ff6eeb 100644 --- a/src/util/dict.c +++ b/src/util/dict.c @@ -45,13 +45,13 @@ #include /* Using Dict_EnableResize() / Dict_DisableResize() we make possible to -* enable/disable resizing of the hash table as needed. This is very important -* for Redis, as we use copy-on-write and don't want to move too much memory -* around when there is a child performing saving operations. -* -* Note that even when dict_can_resize is set to 0, not all resizes are -* prevented: an hash table is still allowed to grow if the ratio between -* the number of elements and the buckets > dict_force_resize_ratio. */ + * enable/disable resizing of the hash table as needed. This is very important + * for Redis, as we use copy-on-write and don't want to move too much memory + * around when there is a child performing saving operations. + * + * Note that even when dict_can_resize is set to 0, not all resizes are + * prevented: an hash table is still allowed to grow if the ratio between + * the number of elements and the buckets > dict_force_resize_ratio. */ static int dict_can_resize = 1; static unsigned int dict_force_resize_ratio = 5; @@ -94,7 +94,7 @@ unsigned int Dict_GetHashFunctionSeed(void) } /* Generic hash function (a popular one from Bernstein). -* I tested a few and this was the best. */ + * I tested a few and this was the best. */ unsigned int Dict_GenHashFunction(const unsigned char *buf, int len) { unsigned int hash = dict_hash_function_seed; @@ -109,7 +109,8 @@ unsigned int Dict_GenCaseHashFunction(const unsigned char *buf, int len) { unsigned int hash = dict_hash_function_seed; while (len--) { - hash = ((hash << 5) + hash) + (tolower(*buf++)); /* hash * 33 + c */ + hash = ((hash << 5) + hash) + + (tolower(*buf++)); /* hash * 33 + c */ } return hash; } @@ -174,7 +175,7 @@ int Dict_Expand(Dict *d, unsigned long size) n.used = 0; n.size = realsize; n.sizemask = realsize - 1; - n.table = calloc(realsize, sizeof(DictEntry*)); + n.table = calloc(realsize, sizeof(DictEntry *)); /* 如果字典的 0 号哈希表未初始化,则将新建的哈希表作为字典的 0 号哈 * 希表,否则,将新建哈希表作为字典的 1 号哈希表,并将它用于 rehash */ @@ -542,14 +543,16 @@ static int Dict_ExpandIfNeeded(Dict *d) return Dict_Expand(d, DICT_HT_INITIAL_SIZE); } /* If we reached the 1:1 ratio, and we are allowed to resize the hash - * table (global setting) or we should avoid it but the ratio between - * elements/buckets is over the "safe" threshold, we resize doubling - * the number of buckets. */ + * table (global setting) or we should avoid it but the ratio between + * elements/buckets is over the "safe" threshold, we resize doubling + * the number of buckets. */ if (d->ht[0].used >= d->ht[0].size && - (dict_can_resize || - d->ht[0].used / d->ht[0].size > dict_force_resize_ratio)) { - return Dict_Expand(d, ((d->ht[0].size > d->ht[0].used) ? - d->ht[0].size : d->ht[0].used) * 2); + (dict_can_resize || + d->ht[0].used / d->ht[0].size > dict_force_resize_ratio)) { + return Dict_Expand( + d, ((d->ht[0].size > d->ht[0].used) ? d->ht[0].size + : d->ht[0].used) * + 2); } return 0; } @@ -558,7 +561,8 @@ static unsigned long Dict_NextPower(unsigned long size) { unsigned long i = DICT_HT_INITIAL_SIZE; - if (size >= LONG_MAX) return LONG_MAX; + if (size >= LONG_MAX) + return LONG_MAX; while (1) { if (i >= size) return i; @@ -609,7 +613,7 @@ static void Dict_PrintStatsHt(DictHashTable *ht) unsigned long clvector[DICT_STATS_VECTLEN]; unsigned long i, slots = 0, chainlen, maxchainlen = 0; if (ht->used == 0) { - LOG("No stats available for empty dictionaries\n"); + Logger_Info("No stats available for empty dictionaries\n"); return; } for (i = 0; i < DICT_STATS_VECTLEN; i++) clvector[i] = 0; @@ -636,21 +640,23 @@ static void Dict_PrintStatsHt(DictHashTable *ht) } totchainlen += chainlen; } - LOG("Hash table stats:\n"); - LOG(" table size: %ld\n", ht->size); - LOG(" number of elements: %ld\n", ht->used); - LOG(" different slots: %ld\n", slots); - LOG(" max chain length: %ld\n", maxchainlen); - LOG(" avg chain length (counted): %.02f\n", (float)totchainlen / slots); - LOG(" avg chain length (computed): %.02f\n", (float)ht->used / slots); - LOG(" Chain length distribution:\n"); + printf("Hash table stats:\n"); + printf(" table size: %ld\n", ht->size); + printf(" number of elements: %ld\n", ht->used); + printf(" different slots: %ld\n", slots); + printf(" max chain length: %ld\n", maxchainlen); + printf(" avg chain length (counted): %.02f\n", + (float)totchainlen / slots); + printf(" avg chain length (computed): %.02f\n", + (float)ht->used / slots); + printf(" Chain length distribution:\n"); for (i = 0; i < DICT_STATS_VECTLEN - 1; i++) { if (clvector[i] == 0) { continue; } - LOG(" %s%ld: %ld (%.02f%%)\n", - (i == DICT_STATS_VECTLEN - 1) ? ">= " : "", - i, clvector[i], ((float)clvector[i] / ht->size) * 100); + printf(" %s%ld: %ld (%.02f%%)\n", + (i == DICT_STATS_VECTLEN - 1) ? ">= " : "", i, + clvector[i], ((float)clvector[i] / ht->size) * 100); } } @@ -658,7 +664,7 @@ void Dict_PrintStats(Dict *d) { Dict_PrintStatsHt(&d->ht[0]); if (Dict_IsRehashing(d)) { - LOG("-- Rehashing into ht[1]:\n"); + printf("-- Rehashing into ht[1]:\n"); Dict_PrintStatsHt(&d->ht[1]); } } @@ -704,20 +710,10 @@ static void StringCopyKeyDict_KeyDestructor(void *privdata, void *key) free(key); } -DictType DictType_StringKey = { - StringCopyKeyDict_KeyHash, - NULL, - NULL, - StringCopyKeyDict_KeyCompare, - NULL, - NULL -}; +DictType DictType_StringKey = { StringCopyKeyDict_KeyHash, NULL, NULL, + StringCopyKeyDict_KeyCompare, NULL, NULL }; DictType DictType_StringCopyKey = { - StringCopyKeyDict_KeyHash, - StringCopyKeyDict_KeyDup, - NULL, - StringCopyKeyDict_KeyCompare, - StringCopyKeyDict_KeyDestructor, - NULL + StringCopyKeyDict_KeyHash, StringCopyKeyDict_KeyDup, NULL, + StringCopyKeyDict_KeyCompare, StringCopyKeyDict_KeyDestructor, NULL }; diff --git a/src/util/logger.c b/src/util/logger.c index bdfb1373c..8d4755c69 100644 --- a/src/util/logger.c +++ b/src/util/logger.c @@ -42,6 +42,7 @@ static struct Logger { wchar_t bufferw[BUFFER_SIZE]; void(*handler)(const char*); void(*handlerw)(const wchar_t*); + LoggerLevel level; LCUI_Mutex mutex; } logger = { 0 }; @@ -60,11 +61,19 @@ static void Win32Logger_LogW(const wchar_t *wcs) #endif -int Logger_Log(const char* fmt, ...) +void Logger_SetLevel(LoggerLevel level) +{ + logger.level = level; +} + +int Logger_Log(LoggerLevel level, const char* fmt, ...) { int len; va_list args; + if (level < logger.level) { + return 0; + } if (!logger.inited) { #ifdef LCUI_BUILD_IN_WIN32 logger.handler = Win32Logger_LogA; @@ -86,11 +95,14 @@ int Logger_Log(const char* fmt, ...) return len; } -int Logger_LogW(const wchar_t* fmt, ...) +int Logger_LogW(LoggerLevel level, const wchar_t* fmt, ...) { int len; va_list args; + if (level < logger.level) { + return 0; + } if (!logger.inited) { #ifdef LCUI_BUILD_IN_WIN32 logger.handlerw = Win32Logger_LogW; diff --git a/src/worker.c b/src/worker.c index c237509f0..25c18b6b7 100644 --- a/src/worker.c +++ b/src/worker.c @@ -146,7 +146,7 @@ int LCUIWorker_RunAsync(LCUI_Worker worker) } worker->active = TRUE; LCUIThread_Create(&worker->thread, LCUIWorker_Thread, worker); - LOG("[worker] worker %u is running\n", worker->thread); + Logger_Info("[worker] worker %u is running\n", worker->thread); return 0; } @@ -155,13 +155,13 @@ void LCUIWorker_Destroy(LCUI_Worker worker) LCUI_Thread thread = worker->thread; if (worker->active) { - LOG("[worker] worker %u is stopping...\n", thread); + Logger_Info("[worker] worker %u is stopping...\n", thread); LCUIMutex_Lock(&worker->mutex); worker->active = FALSE; LCUICond_Signal(&worker->cond); LCUIMutex_Unlock(&worker->mutex); LCUIThread_Join(thread, NULL); - LOG("[worker] worker %u has stopped\n", thread); + Logger_Info("[worker] worker %u has stopped\n", thread); return; } LCUIWorker_ExecDestroy(worker); diff --git a/test/test.h b/test/test.h index a0673e2db..ed6197114 100644 --- a/test/test.h +++ b/test/test.h @@ -2,32 +2,32 @@ extern int tests_count; #define TEST_LOG(format, ...) \ - Logger_Log("[test] %s(): " format, __FUNCTION__, ##__VA_ARGS__) + Logger_Info("[test] %s(): " format, __FUNCTION__, ##__VA_ARGS__) #define PRINT_TEST_RESULT(N) \ - Logger_Log("[test] %d tests, %d pass.\n", tests_count, tests_count + N) + Logger_Info("[test] %d tests, %d pass.\n", tests_count, tests_count + N) -#define CHECK(X) \ - do { \ - tests_count += 1; \ - LOG("[test] %s(): %s. # %s\n", __FUNCTION__, "" #X "", \ - (X) ? "PASS" : (ret -= 1, "NO PASS!")); \ +#define CHECK(X) \ + do { \ + tests_count += 1; \ + Logger_Info("[test] %s(): %s. # %s\n", __FUNCTION__, "" #X "", \ + (X) ? "PASS" : (ret -= 1, "NO PASS!")); \ } while (0); -#define CHECK_WITH_TEXT(TEXT, X) \ - do { \ - tests_count += 1; \ - LOG("[test] %s(): %s. # %s\n", __FUNCTION__, TEXT, \ - (X) ? "PASS" : (ret -= 1, "NO PASS!")); \ +#define CHECK_WITH_TEXT(TEXT, X) \ + do { \ + tests_count += 1; \ + Logger_Info("[test] %s(): %s. # %s\n", __FUNCTION__, TEXT, \ + (X) ? "PASS" : (ret -= 1, "NO PASS!")); \ } while (0); -#define CHECK2(X) \ - do { \ - if (!(X)) { \ - LOG("[test] %s(): %s. # NO PASS!\n", __FUNCTION__, \ - "" #X ""); \ - ret -= 1; \ - } \ +#define CHECK2(X) \ + do { \ + if (!(X)) { \ + Logger_Info("[test] %s(): %s. # NO PASS!\n", \ + __FUNCTION__, "" #X ""); \ + ret -= 1; \ + } \ } while (0); int test_charset(void);