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;
}
std::ostringstream &SimpleLogger::Write(LogLevel lvl)
std::ostringstream &SimpleLogger::Write(LogLevel lvl) noexcept
{
std::lock_guard<std::mutex> lock(get_mutex());
try
level = lvl;
os << "[";
switch (level)
{
level = lvl;
os << "[";
switch (level)
{
case logWARNING:
os << "warn";
break;
case logDEBUG:
case logWARNING:
os << "warn";
break;
case logDEBUG:
#ifndef NDEBUG
os << "debug";
os << "debug";
#endif
break;
default: // logINFO:
os << "info";
break;
}
os << "] ";
}
catch (const std::exception &e)
{
// encapsulate in osrm::exception
throw osrm::exception(std::string(e.what()) + ", getting ostringstream");
break;
default: // logINFO:
os << "info";
break;
}
os << "] ";
return os;
}
@ -127,7 +119,8 @@ SimpleLogger::~SimpleLogger()
<< std::endl;
#endif
break;
default: // logINFO:
case logINFO:
default:
std::cout << os.str() << (is_terminal ? COL_RESET : "") << std::endl;
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.
Redistribution and use in source and binary forms, with or without modification,
@ -64,7 +64,7 @@ class SimpleLogger
virtual ~SimpleLogger();
std::mutex &get_mutex();
std::ostringstream &Write(LogLevel l = logINFO);
std::ostringstream &Write(LogLevel l = logINFO) noexcept;
private:
std::ostringstream os;

View File

@ -78,34 +78,26 @@ std::mutex &SimpleLogger::get_mutex()
return mtx;
}
std::ostringstream &SimpleLogger::Write(LogLevel lvl)
std::ostringstream &SimpleLogger::Write(LogLevel lvl) noexcept
{
std::lock_guard<std::mutex> lock(get_mutex());
try
level = lvl;
os << "[";
switch (level)
{
level = lvl;
os << "[";
switch (level)
{
case logWARNING:
os << "warn";
break;
case logDEBUG:
case logWARNING:
os << "warn";
break;
case logDEBUG:
#ifndef NDEBUG
os << "debug";
os << "debug";
#endif
break;
default: // logINFO:
os << "info";
break;
}
os << "] ";
}
catch (const std::exception &e)
{
// encapsulate in osrm::exception
throw osrm::exception(std::string(e.what()) + ", getting ostringstream");
break;
default: // logINFO:
os << "info";
break;
}
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.
Redistribution and use in source and binary forms, with or without modification,
@ -64,7 +64,7 @@ class SimpleLogger
virtual ~SimpleLogger();
std::mutex &get_mutex();
std::ostringstream &Write(LogLevel l = logINFO);
std::ostringstream &Write(LogLevel l = logINFO) noexcept;
private:
std::ostringstream os;