mark simple logger write function as noexcept.

This commit is contained in:
Dennis Luxen 2015-01-28 10:09:46 +01:00
parent b192678abf
commit 86ca9bd0f9
4 changed files with 34 additions and 49 deletions

View File

@ -78,34 +78,26 @@ std::mutex &SimpleLogger::get_mutex()
return mtx; return mtx;
} }
std::ostringstream &SimpleLogger::Write(LogLevel lvl) std::ostringstream &SimpleLogger::Write(LogLevel lvl) noexcept
{ {
std::lock_guard<std::mutex> lock(get_mutex()); std::lock_guard<std::mutex> lock(get_mutex());
try level = lvl;
os << "[";
switch (level)
{ {
level = lvl; case logWARNING:
os << "["; os << "warn";
switch (level) break;
{ case logDEBUG:
case logWARNING:
os << "warn";
break;
case logDEBUG:
#ifndef NDEBUG #ifndef NDEBUG
os << "debug"; os << "debug";
#endif #endif
break; break;
default: // logINFO: default: // logINFO:
os << "info"; os << "info";
break; break;
}
os << "] ";
}
catch (const std::exception &e)
{
// encapsulate in osrm::exception
throw osrm::exception(std::string(e.what()) + ", getting ostringstream");
} }
os << "] ";
return os; return os;
} }
@ -127,7 +119,8 @@ SimpleLogger::~SimpleLogger()
<< std::endl; << std::endl;
#endif #endif
break; break;
default: // logINFO: case logINFO:
default:
std::cout << os.str() << (is_terminal ? COL_RESET : "") << std::endl; std::cout << os.str() << (is_terminal ? COL_RESET : "") << std::endl;
break; break;
} }

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -64,7 +64,7 @@ class SimpleLogger
virtual ~SimpleLogger(); virtual ~SimpleLogger();
std::mutex &get_mutex(); std::mutex &get_mutex();
std::ostringstream &Write(LogLevel l = logINFO); std::ostringstream &Write(LogLevel l = logINFO) noexcept;
private: private:
std::ostringstream os; std::ostringstream os;

View File

@ -78,34 +78,26 @@ std::mutex &SimpleLogger::get_mutex()
return mtx; return mtx;
} }
std::ostringstream &SimpleLogger::Write(LogLevel lvl) std::ostringstream &SimpleLogger::Write(LogLevel lvl) noexcept
{ {
std::lock_guard<std::mutex> lock(get_mutex()); std::lock_guard<std::mutex> lock(get_mutex());
try level = lvl;
os << "[";
switch (level)
{ {
level = lvl; case logWARNING:
os << "["; os << "warn";
switch (level) break;
{ case logDEBUG:
case logWARNING:
os << "warn";
break;
case logDEBUG:
#ifndef NDEBUG #ifndef NDEBUG
os << "debug"; os << "debug";
#endif #endif
break; break;
default: // logINFO: default: // logINFO:
os << "info"; os << "info";
break; break;
}
os << "] ";
}
catch (const std::exception &e)
{
// encapsulate in osrm::exception
throw osrm::exception(std::string(e.what()) + ", getting ostringstream");
} }
os << "] ";
return os; return os;
} }

View File

@ -1,6 +1,6 @@
/* /*
Copyright (c) 2013, Project OSRM, Dennis Luxen, others Copyright (c) 2015, Project OSRM, Dennis Luxen, others
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without modification,
@ -64,7 +64,7 @@ class SimpleLogger
virtual ~SimpleLogger(); virtual ~SimpleLogger();
std::mutex &get_mutex(); std::mutex &get_mutex();
std::ostringstream &Write(LogLevel l = logINFO); std::ostringstream &Write(LogLevel l = logINFO) noexcept;
private: private:
std::ostringstream os; std::ostringstream os;