提交 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.
......@@ -25,7 +24,6 @@ DEV_FLAGS := $(DO_DEBUG_SYMBOLS) $(DO_SANITIZE) $(DO_OPTIMIZE) $(DO_PEDANTIC)
#
# -DMS_DEVEL enables MS_TRACE().
#
# Settings.
#
......@@ -83,19 +81,18 @@ CXXFLAGS += -std=c++11 -Wall $(DEV_FLAGS)
LDFLAGS += $(foreach lib, $(SYSTEM_LIBS), -l$(lib))
LDFLAGS += $(shell pkg-config --libs "$(PKG_LIBS)")
#
# Targets.
#
# This indicates that "all", APP_NAME, "check_pkg_libs" and "clean" are
# "phony targets". Therefore calling "make XXXX" should execute the content of its
# build rules, even if a newer file named "XXXX" exists.
.PHONY: all $(APP_NAME) check_pkg_libs echo_all_objs clean submodules doc
# This indicates that those names are "phony targets". Therefore calling
# "make XXXX" should execute the content of its build rules, even if a newer
# file named "XXXX" exists.
.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
# "make all" are the same. The target simply depends on $(APP_NAME).
all: $(APP_NAME)
# "make default" are the same. The target simply depends on $(APP_NAME).
default: $(APP_NAME)
# The app depends on the object files (which are automatically built using the
# predefined build rules, nothing needs to be given explicitly for them).
......@@ -103,7 +100,7 @@ all: $(APP_NAME)
# 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)
# $(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)
@ 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)
......@@ -114,7 +111,7 @@ check_pkg_libs:
@ echo "INFO: checking required PKG libraries ($(strip $(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 ..."
# This target removes the built app and the generated object files. The @ symbol
......
......@@ -36,13 +36,8 @@ extern "C"
*
* - MS_TRACE();
* - 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.
*/
......@@ -57,14 +52,16 @@ extern "C"
class Logger
{
public:
static void Init(const std::string name);
static void Init(const std::string id);
static const char* GetProcessName();
static const char* GetProcessMinName();
static void EnableSyslog();
static bool IsSyslogEnabled();
static bool HasDebugLevel();
private:
static std::string processName;
static std::string processMinName;
static bool isSyslogEnabled;
};
......@@ -76,6 +73,12 @@ const char* Logger::GetProcessName()
return Logger::processName.c_str();
}
inline
const char* Logger::GetProcessMinName()
{
return Logger::processMinName.c_str();
}
inline
bool Logger::IsSyslogEnabled()
{
......@@ -98,27 +101,27 @@ bool Logger::HasDebugLevel()
#else
#define _MS_LOG_STR "[%s] %s::%s()"
#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
#define _MS_TO_STDOUT(prefix) \
#define _MS_TO_STDOUT() \
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); \
}
#define _MS_TO_STDOUT_DESC(prefix, desc, ...) \
#define _MS_TO_STDOUT_DESC(desc, ...) \
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); \
}
#define _MS_TO_STDERR_DESC(prefix, desc, ...) \
#define _MS_TO_STDERR_DESC(desc, ...) \
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); \
}
......@@ -143,13 +146,12 @@ bool Logger::HasDebugLevel()
* LOG_DEBUG 7 debug-level messages
*/
#ifdef MS_DEVEL
#define MS_TRACE() \
do \
{ \
_MS_TO_STDOUT("TRACE: "); \
_MS_TO_SYSLOG(LOG_DEBUG, "TRACE: "); \
_MS_TO_STDOUT(); \
_MS_TO_SYSLOG(LOG_DEBUG, "TRACE "); \
} \
while (0)
#else
......@@ -161,8 +163,8 @@ bool Logger::HasDebugLevel()
{ \
if (LOG_DEBUG == MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDOUT_DESC("DEBUG: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_DEBUG, "DEBUG: ", desc, ##__VA_ARGS__); \
_MS_TO_STDOUT_DESC(desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_DEBUG, "DEBUG ", desc, ##__VA_ARGS__); \
} \
} \
while (0)
......@@ -172,8 +174,8 @@ bool Logger::HasDebugLevel()
{ \
if (LOG_INFO <= MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDOUT_DESC("INFO: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_INFO, "INFO: ", desc, ##__VA_ARGS__); \
_MS_TO_STDOUT_DESC(desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_INFO, "INFO ", desc, ##__VA_ARGS__); \
} \
} \
while (0)
......@@ -183,8 +185,8 @@ bool Logger::HasDebugLevel()
{ \
if (LOG_NOTICE <= MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDOUT_DESC("NOTICE: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_NOTICE, "NOTICE: ", desc, ##__VA_ARGS__); \
_MS_TO_STDOUT_DESC(desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_NOTICE, "NOTICE ", desc, ##__VA_ARGS__); \
} \
} \
while (0)
......@@ -194,8 +196,8 @@ bool Logger::HasDebugLevel()
{ \
if (LOG_WARNING <= MS_GET_LOG_LEVEL) \
{ \
_MS_TO_STDERR_DESC("WARN: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_WARNING, "WARN: ", desc, ##__VA_ARGS__); \
_MS_TO_STDERR_DESC(desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_WARNING, "WARN ", desc, ##__VA_ARGS__); \
} \
} \
while (0)
......@@ -203,16 +205,16 @@ bool Logger::HasDebugLevel()
#define MS_ERROR(desc, ...) \
do \
{ \
_MS_TO_STDERR_DESC("ERROR: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_ERR, "ERROR: ", desc, ##__VA_ARGS__); \
_MS_TO_STDERR_DESC(desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_ERR, "ERROR ", desc, ##__VA_ARGS__); \
} \
while (0)
#define MS_CRIT(desc, ...) \
do \
{ \
_MS_TO_STDERR_DESC("CRIT: ", desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_ERR, "CRIT: ", desc, ##__VA_ARGS__); \
_MS_TO_STDERR_DESC(desc, ##__VA_ARGS__); \
_MS_TO_SYSLOG_DESC(LOG_ERR, "CRIT ", desc, ##__VA_ARGS__); \
} \
while (0)
......
......@@ -15,7 +15,7 @@ public:
// Struct holding the configuration.
struct Configuration
{
unsigned int logLevel { LOG_DEBUG };
unsigned int logLevel { LOG_INFO };
bool useSyslog { false };
unsigned int syslogFacility { LOG_USER };
......
......@@ -8,6 +8,7 @@
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#define MS_PROCESS_NAME "mediasoup-worker"
#define MS_PROCESS_MIN_NAME "worker"
#define MS_BYTE uint8_t
#define MS_2BYTES uint16_t
......
......@@ -5,13 +5,15 @@
/* Static variables. */
std::string Logger::processName;
std::string Logger::processMinName;
bool Logger::isSyslogEnabled = false;
/* 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();
}
......
......@@ -3,7 +3,6 @@
CRLF = "\r\n";
SP = 0x20; # Space.
DIGIT = "0".."9";
ALPHA = "a".."z" | "A".."Z";
alphanum = ALPHA | DIGIT;
......@@ -17,7 +16,7 @@
( "25" 0x30..0x35 ); # 0-255.
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.
non_ws_string = ( VCHAR | 0x80..0xFF )+; # String of visible characters.
text = byte_string;
......@@ -51,5 +50,4 @@
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.
}%%
......@@ -30,7 +30,7 @@ int main(int argc, char* argv[])
if (argc == 1)
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);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论