mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-12 13:13:27 +00:00
Add a function to get debug level
This commit is contained in:
parent
0749cc4dac
commit
c83acac32c
@ -108,12 +108,6 @@ namespace Debug
|
||||
class DebugOutputBase : public boost::iostreams::sink
|
||||
{
|
||||
public:
|
||||
DebugOutputBase()
|
||||
{
|
||||
if (CurrentDebugLevel == NoLevel)
|
||||
fillCurrentDebugLevel();
|
||||
}
|
||||
|
||||
virtual std::streamsize write(const char* str, std::streamsize size)
|
||||
{
|
||||
if (size <= 0)
|
||||
@ -174,29 +168,6 @@ namespace Debug
|
||||
return NoLevel;
|
||||
}
|
||||
|
||||
static void fillCurrentDebugLevel()
|
||||
{
|
||||
const char* env = getenv("OPENMW_DEBUG_LEVEL");
|
||||
if (env)
|
||||
{
|
||||
std::string value(env);
|
||||
if (value == "ERROR")
|
||||
CurrentDebugLevel = Error;
|
||||
else if (value == "WARNING")
|
||||
CurrentDebugLevel = Warning;
|
||||
else if (value == "INFO")
|
||||
CurrentDebugLevel = Info;
|
||||
else if (value == "VERBOSE")
|
||||
CurrentDebugLevel = Verbose;
|
||||
else if (value == "DEBUG")
|
||||
CurrentDebugLevel = Debug;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentDebugLevel = Verbose;
|
||||
}
|
||||
|
||||
virtual std::streamsize writeImpl(const char* str, std::streamsize size, Level debugLevel)
|
||||
{
|
||||
return size;
|
||||
@ -380,8 +351,30 @@ namespace Debug
|
||||
return Misc::Locked<std::ostream&>(*rawStderrMutex, getRawStderr());
|
||||
}
|
||||
|
||||
Level getDebugLevel()
|
||||
{
|
||||
if (const char* env = getenv("OPENMW_DEBUG_LEVEL"))
|
||||
{
|
||||
const std::string_view value(env);
|
||||
if (value == "ERROR")
|
||||
return Error;
|
||||
if (value == "WARNING")
|
||||
return Warning;
|
||||
if (value == "INFO")
|
||||
return Info;
|
||||
if (value == "VERBOSE")
|
||||
return Verbose;
|
||||
if (value == "DEBUG")
|
||||
return Debug;
|
||||
}
|
||||
|
||||
return Verbose;
|
||||
}
|
||||
|
||||
void setupLogging(const std::filesystem::path& logDir, std::string_view appName)
|
||||
{
|
||||
CurrentDebugLevel = getDebugLevel();
|
||||
|
||||
#if !(defined(_WIN32) && defined(_DEBUG))
|
||||
const std::string logName = Misc::StringUtils::lowerCase(appName) + ".log";
|
||||
logfile.open(logDir / logName, std::ios::out);
|
||||
|
@ -34,6 +34,8 @@ namespace Debug
|
||||
|
||||
Misc::Locked<std::ostream&> getLockedRawStderr();
|
||||
|
||||
Level getDebugLevel();
|
||||
|
||||
// Redirect cout and cerr to the log file
|
||||
void setupLogging(const std::filesystem::path& logDir, std::string_view appName);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user