mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-23 15:36:49 +00:00
Add a function to get debug level
This commit is contained in:
parent
0749cc4dac
commit
c83acac32c
2 changed files with 24 additions and 29 deletions
|
@ -108,12 +108,6 @@ namespace Debug
|
||||||
class DebugOutputBase : public boost::iostreams::sink
|
class DebugOutputBase : public boost::iostreams::sink
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DebugOutputBase()
|
|
||||||
{
|
|
||||||
if (CurrentDebugLevel == NoLevel)
|
|
||||||
fillCurrentDebugLevel();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual std::streamsize write(const char* str, std::streamsize size)
|
virtual std::streamsize write(const char* str, std::streamsize size)
|
||||||
{
|
{
|
||||||
if (size <= 0)
|
if (size <= 0)
|
||||||
|
@ -174,29 +168,6 @@ namespace Debug
|
||||||
return NoLevel;
|
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)
|
virtual std::streamsize writeImpl(const char* str, std::streamsize size, Level debugLevel)
|
||||||
{
|
{
|
||||||
return size;
|
return size;
|
||||||
|
@ -380,8 +351,30 @@ namespace Debug
|
||||||
return Misc::Locked<std::ostream&>(*rawStderrMutex, getRawStderr());
|
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)
|
void setupLogging(const std::filesystem::path& logDir, std::string_view appName)
|
||||||
{
|
{
|
||||||
|
CurrentDebugLevel = getDebugLevel();
|
||||||
|
|
||||||
#if !(defined(_WIN32) && defined(_DEBUG))
|
#if !(defined(_WIN32) && defined(_DEBUG))
|
||||||
const std::string logName = Misc::StringUtils::lowerCase(appName) + ".log";
|
const std::string logName = Misc::StringUtils::lowerCase(appName) + ".log";
|
||||||
logfile.open(logDir / logName, std::ios::out);
|
logfile.open(logDir / logName, std::ios::out);
|
||||||
|
|
|
@ -34,6 +34,8 @@ namespace Debug
|
||||||
|
|
||||||
Misc::Locked<std::ostream&> getLockedRawStderr();
|
Misc::Locked<std::ostream&> getLockedRawStderr();
|
||||||
|
|
||||||
|
Level getDebugLevel();
|
||||||
|
|
||||||
// Redirect cout and cerr to the log file
|
// Redirect cout and cerr to the log file
|
||||||
void setupLogging(const std::filesystem::path& logDir, std::string_view appName);
|
void setupLogging(const std::filesystem::path& logDir, std::string_view appName);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue