// This file is a part of Framsticks SDK. http://www.framsticks.com/ // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski. // See LICENSE.txt for details. #include "log.h" #include #include "stl-util.h" #include "Convert.h" const char* LOG_LEVEL[] = { "[DEBUG] ", "", "[WARN] ", "[ERROR] ", "[CRITICAL] " }; void logMessage(const char *obj, const char *method, int level, const char *msg) { int line = 0; //all lines except the first one get the "..." prefix const char* nextsep; do { nextsep = strchr(msg, '\n'); if (nextsep == NULL) //last chunk, until the end nextsep = strchr(msg, '\0'); if ((nextsep > msg) && (nextsep[-1] == '\r')) nextsep--; if (line == 0) { if (*nextsep == 0) //there was only one line! no need to modify it in any way. _logMessageSingleLine(obj, method, level, msg); else //first line from multi-line _logMessageSingleLine(obj, method, level, string(msg, nextsep - msg).c_str()); } else //consecutive lines from multi-line _logMessageSingleLine(obj, method, level, (LOG_MULTILINE_CONTINUATION + string(msg, nextsep - msg)).c_str()); //could also add line numbers like ...(3)... but let's keep the prefix short and simple line++; if ((nextsep[0] == '\r') && (nextsep[1] == '\n')) msg = nextsep + 2; else if (*nextsep) msg = nextsep + 1; } while (*nextsep); } void logPrintf_va(const char *obj, const char *method, int level, const char *msgf, va_list va) { string buf = ssprintf_va(msgf, va); logMessage(obj, method, level, buf.c_str()); } void logPrintf(const char *obj, const char *method, int level, const char *msgf, ...) { va_list argptr; va_start(argptr, msgf); logPrintf_va(obj, method, level, msgf, argptr); va_end(argptr); } void log_printf(const char *msgf, ...) { va_list argptr; va_start(argptr, msgf); logPrintf_va("Message", "printf", LOG_INFO, msgf, argptr); va_end(argptr); }