Added stream name to logging

This commit is contained in:
Thulinma 2018-11-21 16:43:23 +01:00
parent ac92e09262
commit 3cb03392e1
7 changed files with 34 additions and 7 deletions

View file

@ -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

View file

@ -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);

View file

@ -34,15 +34,15 @@ static const char * DBG_LVL_LIST[] = {"NONE", "FAIL", "ERROR", "WARN", "INFO", "
#include <errno.h>
#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

View file

@ -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,8 +345,16 @@ namespace Util{
strftime(buffer, 100, "%F %H:%M:%S", timeinfo);
dprintf(out, "%s[%s] ", color_time, buffer);
if (progname && progpid && strlen(progname) && strlen(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)){
dprintf(out, " (%s) ", lineno);

View file

@ -71,7 +71,7 @@ namespace Controller {
rlxLogs->setEndPos(logCounter);
}
}else{
std::cerr << kind << "|MistController|" << getpid() << "||" << message << "\n";
std::cerr << kind << "|MistController|" << getpid() << "|||" << message << "\n";
}
}

View file

@ -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;

View file

@ -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;
}
}