diff --git a/lib/config.cpp b/lib/config.cpp index 9a389871..e5889e19 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -37,6 +37,7 @@ bool Util::Config::is_active = false; static Socket::Server * serv_sock_pointer = 0; unsigned int Util::Config::printDebugLevel = DEBUG;// +std::string Util::Config::streamName; Util::Config::Config() { //global options here diff --git a/lib/config.h b/lib/config.h index bdefe569..35e3e49b 100644 --- a/lib/config.h +++ b/lib/config.h @@ -24,6 +24,7 @@ namespace Util { //variables static bool is_active; ///< Set to true by activate(), set to false by the signal handler. static unsigned int printDebugLevel; + static std::string streamName; ///< Used by debug messages to identify the stream name //functions Config(); Config(std::string cmd); diff --git a/lib/defines.h b/lib/defines.h index 201faf87..ce3572f3 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -34,15 +34,15 @@ static const char * DBG_LVL_LIST[] = {"NONE", "FAIL", "ERROR", "WARN", "INFO", " #include #if DEBUG >= DLVL_DEVEL -#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s|%s|%d|%s:%d|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, getpid(), __FILE__, __LINE__, ##__VA_ARGS__);} +#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s|%s|%d|%s:%d|%s|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, getpid(), __FILE__, __LINE__, Util::Config::streamName.c_str(), ##__VA_ARGS__);} #else -#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s|%s|%d||" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, getpid(), ##__VA_ARGS__);} +#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s|%s|%d||%s|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, getpid(), Util::Config::streamName.c_str(), ##__VA_ARGS__);} #endif #else #if DEBUG >= DLVL_DEVEL -#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s||%d|%s:%d|" msg "\n", DBG_LVL_LIST[lvl], getpid(), __FILE__, __LINE__, ##__VA_ARGS__);} +#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s||%d|%s:%d|%s|" msg "\n", DBG_LVL_LIST[lvl], getpid(), __FILE__, __LINE__, Util::Config::streamName.c_str(), ##__VA_ARGS__);} #else -#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s||%d||" msg "\n", DBG_LVL_LIST[lvl], getpid(), ##__VA_ARGS__);} +#define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s||%d||%s|" msg "\n", DBG_LVL_LIST[lvl], getpid(), Util::Config::streamName.c_str(), ##__VA_ARGS__);} #endif #endif diff --git a/lib/util.cpp b/lib/util.cpp index 7cf4d868..7cc25382 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -250,10 +250,12 @@ namespace Util{ void logParser(int in, int out, bool colored, void callback(std::string, std::string, bool)){ char buf[1024]; FILE *output = fdopen(in, "r"); - char *color_time, *color_msg, *color_end, *CONF_msg, *FAIL_msg, *ERROR_msg, *WARN_msg, *INFO_msg; + char *color_time, *color_msg, *color_end, *color_strm, *CONF_msg, *FAIL_msg, *ERROR_msg, *WARN_msg, *INFO_msg; if (colored){ color_end = (char*)"\033[0m"; if (getenv("MIST_COLOR_END")){color_end = getenv("MIST_COLOR_END");} + color_strm = (char*)"\033[0m"; + if (getenv("MIST_COLOR_STREAM")){color_strm = getenv("MIST_COLOR_STREAM");} color_time = (char*)"\033[2m"; if (getenv("MIST_COLOR_TIME")){color_time = getenv("MIST_COLOR_TIME");} CONF_msg = (char*)"\033[0;1;37m"; @@ -268,6 +270,7 @@ namespace Util{ if (getenv("MIST_COLOR_INFO")){INFO_msg = getenv("MIST_COLOR_INFO");} }else{ color_end = (char*)""; + color_strm = (char*)""; color_time = (char*)""; CONF_msg = (char*)""; FAIL_msg = (char*)""; @@ -281,6 +284,7 @@ namespace Util{ char * progname = 0; char * progpid = 0; char * lineno = 0; + char * strmNm = 0; char * message = 0; while (i < 9 && buf[i] != '|' && buf[i] != 0){++i;} if (buf[i] == '|'){ @@ -301,11 +305,22 @@ namespace Util{ lineno = buf+i;//lineno starts here } while (i < 180 && buf[i] != '|' && buf[i] != 0){++i;} + if (buf[i] == '|'){ + buf[i] = 0;//insert null byte + ++i; + strmNm = buf+i;//stream name starts here + } + while (i < 380 && buf[i] != '|' && buf[i] != 0){++i;} if (buf[i] == '|'){ buf[i] = 0;//insert null byte ++i; message = buf+i;//message starts here } + if (!message){ + message = strmNm; + strmNm = 0; + if (message){i = message-buf;} + } //find end of line, insert null byte unsigned int j = i; while (j < 1023 && buf[j] != '\n' && buf[j] != 0){++j;} @@ -330,7 +345,15 @@ namespace Util{ strftime(buffer, 100, "%F %H:%M:%S", timeinfo); dprintf(out, "%s[%s] ", color_time, buffer); if (progname && progpid && strlen(progname) && strlen(progpid)){ - dprintf(out, "%s (%s) ", progname, progpid); + if (strmNm && strlen(strmNm)){ + dprintf(out, "%s:%s%s%s (%s) ", progname, color_strm, strmNm, color_time, progpid); + }else{ + dprintf(out, "%s (%s) ", progname, progpid); + } + }else{ + if (strmNm && strlen(strmNm)){ + dprintf(out, "%s%s%s ", color_strm, strmNm, color_time); + } } dprintf(out, "%s%s: %s%s", color_msg, kind, message, color_end); if (lineno && strlen(lineno)){ diff --git a/src/controller/controller_storage.cpp b/src/controller/controller_storage.cpp index 10f61d79..5cef6a10 100644 --- a/src/controller/controller_storage.cpp +++ b/src/controller/controller_storage.cpp @@ -71,7 +71,7 @@ namespace Controller { rlxLogs->setEndPos(logCounter); } }else{ - std::cerr << kind << "|MistController|" << getpid() << "||" << message << "\n"; + std::cerr << kind << "|MistController|" << getpid() << "|||" << message << "\n"; } } diff --git a/src/input/input.cpp b/src/input/input.cpp index 52e17f6e..e2abbd04 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -95,6 +95,7 @@ namespace Mist { int Input::boot(int argc, char * argv[]){ if (!(config->parseArgs(argc, argv))){return 1;} streamName = nProxy.streamName = config->getString("streamname"); + Util::Config::streamName = streamName; if (config->getBool("json")) { std::cout << capa.toString() << std::endl; diff --git a/src/output/output.cpp b/src/output/output.cpp index 090522fb..1605f30d 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -79,6 +79,7 @@ namespace Mist{ //If we have a streamname option, set internal streamname to that option if (!streamName.size() && config->hasOption("streamname")){ streamName = config->getString("streamname"); + Util::Config::streamName = streamName; } }