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

Worker: Add LogLevel enum.

上级 a675da25
#ifndef MS_LOG_LEVEL_H
#define MS_LOG_LEVEL_H
#include "common.h"
enum class LogLevel : uint8_t
{
DEBUG = 2,
WARN = 1,
ERROR = 0
};
#endif
#ifndef MS_LOGGER_H #ifndef MS_LOGGER_H
#define MS_LOGGER_H #define MS_LOGGER_H
#include "common.h" #include "LogLevel.h"
#include "Settings.h" #include "Settings.h"
#include "handles/UnixStreamSocket.h" #include "handles/UnixStreamSocket.h"
#include "Channel/UnixStreamSocket.h" #include "Channel/UnixStreamSocket.h"
...@@ -39,12 +39,6 @@ ...@@ -39,12 +39,6 @@
*/ */
// #define MS_DEVEL // #define MS_DEVEL
/*
* This macro must point to a unsigned int function, method or variable that
* returns the logging level.
*/
#define MS_CURRENT_LOG_LEVEL Settings::configuration.logLevel
class Logger class Logger
{ {
public: public:
...@@ -62,7 +56,7 @@ public: ...@@ -62,7 +56,7 @@ public:
inline inline
bool Logger::HasDebugLevel() bool Logger::HasDebugLevel()
{ {
return (MS_LOG_LEVEL_DEBUG == MS_CURRENT_LOG_LEVEL); return (LogLevel::DEBUG == Settings::configuration.logLevel);
} }
// NOTE: Each file including Logger.h MUST define its own MS_CLASS macro. // NOTE: Each file including Logger.h MUST define its own MS_CLASS macro.
...@@ -103,7 +97,7 @@ bool Logger::HasDebugLevel() ...@@ -103,7 +97,7 @@ bool Logger::HasDebugLevel()
#define MS_DEBUG(desc, ...) \ #define MS_DEBUG(desc, ...) \
do \ do \
{ \ { \
if (MS_LOG_LEVEL_DEBUG == MS_CURRENT_LOG_LEVEL) \ if (LogLevel::DEBUG == Settings::configuration.logLevel) \
{ \ { \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
...@@ -114,7 +108,7 @@ bool Logger::HasDebugLevel() ...@@ -114,7 +108,7 @@ bool Logger::HasDebugLevel()
#define MS_DEBUG_STD(desc, ...) \ #define MS_DEBUG_STD(desc, ...) \
do \ do \
{ \ { \
if (MS_LOG_LEVEL_DEBUG == MS_CURRENT_LOG_LEVEL) \ if (LogLevel::DEBUG == Settings::configuration.logLevel) \
{ \ { \
std::fprintf(stdout, _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \ std::fprintf(stdout, _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stdout); \ std::fflush(stdout); \
...@@ -125,7 +119,7 @@ bool Logger::HasDebugLevel() ...@@ -125,7 +119,7 @@ bool Logger::HasDebugLevel()
#define MS_WARN(desc, ...) \ #define MS_WARN(desc, ...) \
do \ do \
{ \ { \
if (MS_LOG_LEVEL_WARN <= MS_CURRENT_LOG_LEVEL) \ if (LogLevel::WARN <= Settings::configuration.logLevel) \
{ \ { \
int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ int ms_logger_written = std::snprintf(Logger::buffer, MS_LOGGER_BUFFER_SIZE, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, ms_logger_written); \ Logger::channel->SendLog(Logger::buffer, ms_logger_written); \
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define MS_SETTINGS_H #define MS_SETTINGS_H
#include "common.h" #include "common.h"
#include "logLevel.h"
#include "Channel/Request.h" #include "Channel/Request.h"
#include <map> #include <map>
#include <string> #include <string>
...@@ -13,7 +14,7 @@ public: ...@@ -13,7 +14,7 @@ public:
// Struct holding the configuration. // Struct holding the configuration.
struct Configuration struct Configuration
{ {
uint8_t logLevel { MS_LOG_LEVEL_DEBUG }; LogLevel logLevel { LogLevel::DEBUG };
std::string rtcListenIPv4; std::string rtcListenIPv4;
std::string rtcListenIPv6; std::string rtcListenIPv6;
uint16_t rtcMinPort { 10000 }; uint16_t rtcMinPort { 10000 };
...@@ -42,8 +43,8 @@ public: ...@@ -42,8 +43,8 @@ public:
static struct Configuration configuration; static struct Configuration configuration;
private: private:
static std::map<std::string, uint8_t> string2LogLevel; static std::map<std::string, LogLevel> string2LogLevel;
static std::map<uint8_t, std::string> logLevel2String; static std::map<LogLevel, std::string> logLevel2String;
}; };
#endif #endif
...@@ -11,10 +11,6 @@ ...@@ -11,10 +11,6 @@
#define MS_APP_NAME "mediasoup" #define MS_APP_NAME "mediasoup"
#define MS_PROCESS_NAME "mediasoup-worker" #define MS_PROCESS_NAME "mediasoup-worker"
#define MS_LOG_LEVEL_DEBUG 2
#define MS_LOG_LEVEL_WARN 1
#define MS_LOG_LEVEL_ERROR 0
// Detect Little-Endian or Big-Endian CPU. // Detect Little-Endian or Big-Endian CPU.
// NOTE: If the macro MS_LITTLE_ENDIAN or MS_BIG_ENDIAN is already defined // NOTE: If the macro MS_LITTLE_ENDIAN or MS_BIG_ENDIAN is already defined
// then don't autodetect it. // then don't autodetect it.
......
...@@ -24,17 +24,17 @@ bool IsBindableIP(const std::string &ip, int family, int* _bind_err); ...@@ -24,17 +24,17 @@ bool IsBindableIP(const std::string &ip, int family, int* _bind_err);
/* Class variables. */ /* Class variables. */
struct Settings::Configuration Settings::configuration; struct Settings::Configuration Settings::configuration;
std::map<std::string, uint8_t> Settings::string2LogLevel = std::map<std::string, LogLevel> Settings::string2LogLevel =
{ {
{ "debug", MS_LOG_LEVEL_DEBUG }, { "debug", LogLevel::DEBUG },
{ "warn", MS_LOG_LEVEL_WARN }, { "warn", LogLevel::WARN },
{ "error", MS_LOG_LEVEL_ERROR } { "error", LogLevel::ERROR }
}; };
std::map<uint8_t, std::string> Settings::logLevel2String = std::map<LogLevel, std::string> Settings::logLevel2String =
{ {
{ MS_LOG_LEVEL_DEBUG, "debug" }, { LogLevel::DEBUG, "debug" },
{ MS_LOG_LEVEL_WARN, "warn" }, { LogLevel::WARN, "warn" },
{ MS_LOG_LEVEL_ERROR, "error" } { LogLevel::ERROR, "error" }
}; };
/* Class methods. */ /* Class methods. */
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论