Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复全局变量初始化顺序问题 #699

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions muduo/base/Logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ Logger::LogLevel initLogLevel()
return Logger::INFO;
}

Logger::LogLevel g_logLevel = initLogLevel();
// Logger::LogLevel g_logLevel = initLogLevel();
static Logger::LogLevel& g_logLevel()
{
static Logger::LogLevel g_logLevel = initLogLevel();
return g_logLevel;
}
Logger::LogLevel Logger::logLevel()
{
return g_logLevel();
}

const char* LogLevelName[Logger::NUM_LOG_LEVELS] =
{
Expand Down Expand Up @@ -207,7 +216,7 @@ Logger::~Logger()

void Logger::setLogLevel(Logger::LogLevel level)
{
g_logLevel = level;
g_logLevel() = level;
}

void Logger::setOutput(OutputFunc out)
Expand Down
8 changes: 1 addition & 7 deletions muduo/base/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Logger

static LogLevel logLevel();
static void setLogLevel(LogLevel level);

typedef void (*OutputFunc)(const char* msg, int len);
typedef void (*FlushFunc)();
static void setOutput(OutputFunc);
Expand Down Expand Up @@ -98,12 +98,6 @@ class Impl

};

extern Logger::LogLevel g_logLevel;

inline Logger::LogLevel Logger::logLevel()
{
return g_logLevel;
}

//
// CAUTION: do not write:
Expand Down