提交 c290cb2b authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

worker: rename process name to mediasoup-worker and improve logger.

上级 57fe729f
APP_NAME := mediasoup APP_NAME := mediasoup-worker
# #
# Compiler. # Compiler.
...@@ -25,7 +24,6 @@ DEV_FLAGS := $(DO_DEBUG_SYMBOLS) $(DO_SANITIZE) $(DO_OPTIMIZE) $(DO_PEDANTIC) ...@@ -25,7 +24,6 @@ DEV_FLAGS := $(DO_DEBUG_SYMBOLS) $(DO_SANITIZE) $(DO_OPTIMIZE) $(DO_PEDANTIC)
# #
# -DMS_DEVEL enables MS_TRACE(). # -DMS_DEVEL enables MS_TRACE().
# #
# Settings. # Settings.
# #
...@@ -83,19 +81,18 @@ CXXFLAGS += -std=c++11 -Wall $(DEV_FLAGS) ...@@ -83,19 +81,18 @@ CXXFLAGS += -std=c++11 -Wall $(DEV_FLAGS)
LDFLAGS += $(foreach lib, $(SYSTEM_LIBS), -l$(lib)) LDFLAGS += $(foreach lib, $(SYSTEM_LIBS), -l$(lib))
LDFLAGS += $(shell pkg-config --libs "$(PKG_LIBS)") LDFLAGS += $(shell pkg-config --libs "$(PKG_LIBS)")
# #
# Targets. # Targets.
# #
# This indicates that "all", APP_NAME, "check_pkg_libs" and "clean" are # This indicates that those names are "phony targets". Therefore calling
# "phony targets". Therefore calling "make XXXX" should execute the content of its # "make XXXX" should execute the content of its build rules, even if a newer
# build rules, even if a newer file named "XXXX" exists. # file named "XXXX" exists.
.PHONY: all $(APP_NAME) check_pkg_libs echo_all_objs clean submodules doc .PHONY: default $(APP_NAME) check_pkg_libs echo_compiling_all_objs clean submodules doc
# This is first build rule in the Makefile, and so executing "make" and executing # This is first build rule in the Makefile, and so executing "make" and executing
# "make all" are the same. The target simply depends on $(APP_NAME). # "make default" are the same. The target simply depends on $(APP_NAME).
all: $(APP_NAME) default: $(APP_NAME)
# The app depends on the object files (which are automatically built using the # The app depends on the object files (which are automatically built using the
# predefined build rules, nothing needs to be given explicitly for them). # predefined build rules, nothing needs to be given explicitly for them).
...@@ -103,7 +100,7 @@ all: $(APP_NAME) ...@@ -103,7 +100,7 @@ all: $(APP_NAME)
# the same name as the app. Note that LINK.cc makes use of CXX, CXXFLAGS, # the same name as the app. Note that LINK.cc makes use of CXX, CXXFLAGS,
# LFLAGS, etc. LINK.cc is usually defined as: $(CXX) $(CXXFLAGS) $(CPPFLAGS) # LFLAGS, etc. LINK.cc is usually defined as: $(CXX) $(CXXFLAGS) $(CPPFLAGS)
# $(LDFLAGS) $(TARGET_ARCH). # $(LDFLAGS) $(TARGET_ARCH).
$(APP_NAME): check_pkg_libs echo_all_objs $(ALL_OBJS) $(APP_NAME): check_pkg_libs echo_compiling_all_objs $(ALL_OBJS)
@ mkdir -p $(APP_BIN_DIR) @ mkdir -p $(APP_BIN_DIR)
@ echo "INFO: linking .o objects and libraries into $(APP_BIN_DIR)/$(APP_NAME) ..." @ echo "INFO: linking .o objects and libraries into $(APP_BIN_DIR)/$(APP_NAME) ..."
$(LINK.cc) $(ALL_OBJS) $(DEP_LIBS) -o $(APP_BIN_DIR)/$(APP_NAME) $(LINK.cc) $(ALL_OBJS) $(DEP_LIBS) -o $(APP_BIN_DIR)/$(APP_NAME)
...@@ -114,7 +111,7 @@ check_pkg_libs: ...@@ -114,7 +111,7 @@ check_pkg_libs:
@ echo "INFO: checking required PKG libraries ($(strip $(PKG_LIBS))) ..." @ echo "INFO: checking required PKG libraries ($(strip $(PKG_LIBS))) ..."
@ pkg-config --exists --print-errors "$(PKG_LIBS)" @ pkg-config --exists --print-errors "$(PKG_LIBS)"
echo_all_objs: echo_compiling_all_objs:
@ echo "INFO: compiling source files into .o object files ..." @ echo "INFO: compiling source files into .o object files ..."
# This target removes the built app and the generated object files. The @ symbol # This target removes the built app and the generated object files. The @ symbol
......
...@@ -36,13 +36,8 @@ extern "C" ...@@ -36,13 +36,8 @@ extern "C"
* *
* - MS_TRACE(); * - MS_TRACE();
* - MS_DEBUG("starting worker %d", num); * - MS_DEBUG("starting worker %d", num);
*
* Output:
* TRACE: [worker #1] Worker.cpp:93 | void Worker::Run()
* DEBUG: [worker #1] Worker.cpp:94 | void Worker::Run() | starting worker 1
*/ */
/* /*
* Call the compiler with -DMS_DEVEL for more verbose logs. * Call the compiler with -DMS_DEVEL for more verbose logs.
*/ */
...@@ -57,14 +52,16 @@ extern "C" ...@@ -57,14 +52,16 @@ extern "C"
class Logger class Logger
{ {
public: public:
static void Init(const std::string name); static void Init(const std::string id);
static const char* GetProcessName(); static const char* GetProcessName();
static const char* GetProcessMinName();
static void EnableSyslog(); static void EnableSyslog();
static bool IsSyslogEnabled(); static bool IsSyslogEnabled();
static bool HasDebugLevel(); static bool HasDebugLevel();
private: private:
static std::string processName; static std::string processName;
static std::string processMinName;
static bool isSyslogEnabled; static bool isSyslogEnabled;
}; };
...@@ -76,6 +73,12 @@ const char* Logger::GetProcessName() ...@@ -76,6 +73,12 @@ const char* Logger::GetProcessName()
return Logger::processName.c_str(); return Logger::processName.c_str();
} }
inline
const char* Logger::GetProcessMinName()
{
return Logger::processMinName.c_str();
}
inline inline
bool Logger::IsSyslogEnabled() bool Logger::IsSyslogEnabled()
{ {
...@@ -98,27 +101,27 @@ bool Logger::HasDebugLevel() ...@@ -98,27 +101,27 @@ bool Logger::HasDebugLevel()
#else #else
#define _MS_LOG_STR "[%s] %s::%s()" #define _MS_LOG_STR "[%s] %s::%s()"
#define _MS_LOG_STR_DESC _MS_LOG_STR " | " #define _MS_LOG_STR_DESC _MS_LOG_STR " | "
#define _MS_LOG_ARG Logger::GetProcessName(), MS_CLASS, __FUNCTION__ #define _MS_LOG_ARG Logger::GetProcessMinName(), MS_CLASS, __FUNCTION__
#endif #endif
#define _MS_TO_STDOUT(prefix) \ #define _MS_TO_STDOUT() \
if (!Logger::IsSyslogEnabled()) \ if (!Logger::IsSyslogEnabled()) \
{ \ { \
std::fprintf(stdout, prefix _MS_LOG_STR "\n", _MS_LOG_ARG); \ std::fprintf(stdout, _MS_LOG_STR "\n", _MS_LOG_ARG); \
fflush(stdout); \ fflush(stdout); \
} }
#define _MS_TO_STDOUT_DESC(prefix, desc, ...) \ #define _MS_TO_STDOUT_DESC(desc, ...) \
if (!Logger::IsSyslogEnabled()) \ if (!Logger::IsSyslogEnabled()) \
{ \ { \
std::fprintf(stdout, prefix _MS_LOG_STR_DESC desc "\n", _MS_LOG_ARG, ##__VA_ARGS__); \ std::fprintf(stdout, _MS_LOG_STR_DESC desc "\n", _MS_LOG_ARG, ##__VA_ARGS__); \
fflush(stdout); \ fflush(stdout); \
} }
#define _MS_TO_STDERR_DESC(prefix, desc, ...) \ #define _MS_TO_STDERR_DESC(desc, ...) \
if (!Logger::IsSyslogEnabled()) \ if (!Logger::IsSyslogEnabled()) \
{ \ { \
std::fprintf(stderr, prefix _MS_LOG_STR_DESC desc "\n", _MS_LOG_ARG, ##__VA_ARGS__); \ std::fprintf(stderr, _MS_LOG_STR_DESC desc "\n", _MS_LOG_ARG, ##__VA_ARGS__); \
fflush(stderr); \ fflush(stderr); \
} }
...@@ -143,13 +146,12 @@ bool Logger::HasDebugLevel() ...@@ -143,13 +146,12 @@ bool Logger::HasDebugLevel()
* LOG_DEBUG 7 debug-level messages * LOG_DEBUG 7 debug-level messages
*/ */
#ifdef MS_DEVEL #ifdef MS_DEVEL
#define MS_TRACE() \ #define MS_TRACE() \
do \ do \
{ \ { \
_MS_TO_STDOUT("TRACE: "); \ _MS_TO_STDOUT(); \
_MS_TO_SYSLOG(LOG_DEBUG, "TRACE: "); \ _MS_TO_SYSLOG(LOG_DEBUG, "TRACE "); \
} \ } \
while (0) while (0)
#else #else
...@@ -161,8 +163,8 @@ bool Logger::HasDebugLevel() ...@@ -161,8 +163,8 @@ bool Logger::HasDebugLevel()
{ \ { \
if (LOG_DEBUG == MS_GET_LOG_LEVEL) \ if (LOG_DEBUG == MS_GET_LOG_LEVEL) \
{ \ { \
_MS_TO_STDOUT_DESC("DEBUG: ", desc, ##__VA_ARGS__); \ _MS_TO_STDOUT_DESC(desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_DEBUG, "DEBUG: ", desc, ##__VA_ARGS__); \ _MS_TO_SYSLOG_DESC(LOG_DEBUG, "DEBUG ", desc, ##__VA_ARGS__); \
} \ } \
} \ } \
while (0) while (0)
...@@ -172,8 +174,8 @@ bool Logger::HasDebugLevel() ...@@ -172,8 +174,8 @@ bool Logger::HasDebugLevel()
{ \ { \
if (LOG_INFO <= MS_GET_LOG_LEVEL) \ if (LOG_INFO <= MS_GET_LOG_LEVEL) \
{ \ { \
_MS_TO_STDOUT_DESC("INFO: ", desc, ##__VA_ARGS__); \ _MS_TO_STDOUT_DESC(desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_INFO, "INFO: ", desc, ##__VA_ARGS__); \ _MS_TO_SYSLOG_DESC(LOG_INFO, "INFO ", desc, ##__VA_ARGS__); \
} \ } \
} \ } \
while (0) while (0)
...@@ -183,8 +185,8 @@ bool Logger::HasDebugLevel() ...@@ -183,8 +185,8 @@ bool Logger::HasDebugLevel()
{ \ { \
if (LOG_NOTICE <= MS_GET_LOG_LEVEL) \ if (LOG_NOTICE <= MS_GET_LOG_LEVEL) \
{ \ { \
_MS_TO_STDOUT_DESC("NOTICE: ", desc, ##__VA_ARGS__); \ _MS_TO_STDOUT_DESC(desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_NOTICE, "NOTICE: ", desc, ##__VA_ARGS__); \ _MS_TO_SYSLOG_DESC(LOG_NOTICE, "NOTICE ", desc, ##__VA_ARGS__); \
} \ } \
} \ } \
while (0) while (0)
...@@ -194,8 +196,8 @@ bool Logger::HasDebugLevel() ...@@ -194,8 +196,8 @@ bool Logger::HasDebugLevel()
{ \ { \
if (LOG_WARNING <= MS_GET_LOG_LEVEL) \ if (LOG_WARNING <= MS_GET_LOG_LEVEL) \
{ \ { \
_MS_TO_STDERR_DESC("WARN: ", desc, ##__VA_ARGS__); \ _MS_TO_STDERR_DESC(desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_WARNING, "WARN: ", desc, ##__VA_ARGS__); \ _MS_TO_SYSLOG_DESC(LOG_WARNING, "WARN ", desc, ##__VA_ARGS__); \
} \ } \
} \ } \
while (0) while (0)
...@@ -203,16 +205,16 @@ bool Logger::HasDebugLevel() ...@@ -203,16 +205,16 @@ bool Logger::HasDebugLevel()
#define MS_ERROR(desc, ...) \ #define MS_ERROR(desc, ...) \
do \ do \
{ \ { \
_MS_TO_STDERR_DESC("ERROR: ", desc, ##__VA_ARGS__); \ _MS_TO_STDERR_DESC(desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_ERR, "ERROR: ", desc, ##__VA_ARGS__); \ _MS_TO_SYSLOG_DESC(LOG_ERR, "ERROR ", desc, ##__VA_ARGS__); \
} \ } \
while (0) while (0)
#define MS_CRIT(desc, ...) \ #define MS_CRIT(desc, ...) \
do \ do \
{ \ { \
_MS_TO_STDERR_DESC("CRIT: ", desc, ##__VA_ARGS__); \ _MS_TO_STDERR_DESC(desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_ERR, "CRIT: ", desc, ##__VA_ARGS__); \ _MS_TO_SYSLOG_DESC(LOG_ERR, "CRIT ", desc, ##__VA_ARGS__); \
} \ } \
while (0) while (0)
......
...@@ -15,7 +15,7 @@ public: ...@@ -15,7 +15,7 @@ public:
// Struct holding the configuration. // Struct holding the configuration.
struct Configuration struct Configuration
{ {
unsigned int logLevel { LOG_DEBUG }; unsigned int logLevel { LOG_INFO };
bool useSyslog { false }; bool useSyslog { false };
unsigned int syslogFacility { LOG_USER }; unsigned int syslogFacility { LOG_USER };
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs() #include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#define MS_PROCESS_NAME "mediasoup-worker" #define MS_PROCESS_NAME "mediasoup-worker"
#define MS_PROCESS_MIN_NAME "worker"
#define MS_BYTE uint8_t #define MS_BYTE uint8_t
#define MS_2BYTES uint16_t #define MS_2BYTES uint16_t
......
...@@ -5,13 +5,15 @@ ...@@ -5,13 +5,15 @@
/* Static variables. */ /* Static variables. */
std::string Logger::processName; std::string Logger::processName;
std::string Logger::processMinName;
bool Logger::isSyslogEnabled = false; bool Logger::isSyslogEnabled = false;
/* Static methods. */ /* Static methods. */
void Logger::Init(const std::string name) void Logger::Init(const std::string id)
{ {
Logger::processName = name; Logger::processName = MS_PROCESS_NAME "@" + id;
Logger::processMinName = MS_PROCESS_MIN_NAME "@" + id;
MS_TRACE(); MS_TRACE();
} }
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
CRLF = "\r\n"; CRLF = "\r\n";
SP = 0x20; # Space. SP = 0x20; # Space.
DIGIT = "0".."9"; DIGIT = "0".."9";
ALPHA = "a".."z" | "A".."Z"; ALPHA = "a".."z" | "A".."Z";
alphanum = ALPHA | DIGIT; alphanum = ALPHA | DIGIT;
...@@ -17,7 +16,7 @@ ...@@ -17,7 +16,7 @@
( "25" 0x30..0x35 ); # 0-255. ( "25" 0x30..0x35 ); # 0-255.
token = ( 0x21 | 0x23..0x27 | 0x2A..0x2B | 0x2D..0x2E | 0x30..0x39 | 0x41..0x5A | token = ( 0x21 | 0x23..0x27 | 0x2A..0x2B | 0x2D..0x2E | 0x30..0x39 | 0x41..0x5A |
0x5E..0x7E )+; 0x5E..0x7E )+;
byte_string = ( 0x01..0x09 | 0x0B..0x0C | 0x0E..0xFF )+; # Any byte except NULL, CR or LF. byte_string = ( 0x01..0x09 | 0x0B..0x0C | 0x0E..0xFF )+; # Any byte except NULL, CR or LF.
non_ws_string = ( VCHAR | 0x80..0xFF )+; # String of visible characters. non_ws_string = ( VCHAR | 0x80..0xFF )+; # String of visible characters.
text = byte_string; text = byte_string;
...@@ -51,5 +50,4 @@ ...@@ -51,5 +50,4 @@
unicast_address = IPv4address | IPv6address | FQDN; # NOTE: let's remove non_ws_string. unicast_address = IPv4address | IPv6address | FQDN; # NOTE: let's remove non_ws_string.
multicast_address = IPv4address_multicast | IPv6address_multicast | FQDN; # NOTE: let's remove non_ws_string. multicast_address = IPv4address_multicast | IPv6address_multicast | FQDN; # NOTE: let's remove non_ws_string.
}%% }%%
...@@ -30,7 +30,7 @@ int main(int argc, char* argv[]) ...@@ -30,7 +30,7 @@ int main(int argc, char* argv[])
if (argc == 1) if (argc == 1)
MS_EXIT_FAILURE("process id must be given as first argument"); MS_EXIT_FAILURE("process id must be given as first argument");
id = MS_PROCESS_NAME "#" + std::string(argv[1]); id = std::string(argv[1]);
Logger::Init(id); Logger::Init(id);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论