2013-10-05 06:14:35 +02:00
|
|
|
/** ==========================================================================
|
|
|
|
* 2012 by KjellKod.cc. This is PUBLIC DOMAIN to use at your own risk and comes
|
|
|
|
* with no warranties. This code is yours to share, use and modify with no
|
|
|
|
* strings attached and no restrictions or obligations.
|
|
|
|
* ============================================================================
|
|
|
|
* Filename:g2loglevels.cpp Part of Framework for Logging and Design By Contract
|
|
|
|
* Created: 2012 by Kjell Hedström
|
|
|
|
*
|
|
|
|
* PUBLIC DOMAIN and Not copywrited. First published at KjellKod.cc
|
|
|
|
* ********************************************* */
|
|
|
|
|
|
|
|
#include "g2loglevels.hpp"
|
2013-12-10 22:57:04 +01:00
|
|
|
#include "g2log.hpp"
|
2013-10-05 06:14:35 +02:00
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
namespace g2
|
|
|
|
{
|
|
|
|
namespace internal {
|
2013-10-31 10:28:08 +01:00
|
|
|
bool wasFatal(const LEVELS& level) {
|
2014-01-09 06:48:18 +01:00
|
|
|
return level.value >= FATAL.value;
|
2013-10-31 10:28:08 +01:00
|
|
|
}
|
2014-01-09 06:48:18 +01:00
|
|
|
|
|
|
|
// All levels are by default ON: i.e. for DEBUG, INFO, WARNING, FATAL
|
|
|
|
constexpr const int size = FATAL.value+1;
|
|
|
|
std::atomic<bool> g_log_level_status[4]{{true}, {true}, {true},{true}};
|
|
|
|
static_assert(4 == size, "Mismatch between number of logging levels and their use");
|
2013-10-05 06:14:35 +02:00
|
|
|
} // internal
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef G2_DYNAMIC_LOGGING
|
|
|
|
void setLogLevel(LEVELS log_level, bool enabled)
|
|
|
|
{
|
|
|
|
int level = log_level.value;
|
|
|
|
CHECK((level >= DEBUG.value) && (level <= FATAL.value));
|
2014-01-09 06:48:18 +01:00
|
|
|
internal::g_log_level_status[level].store(enabled, std::memory_order_release);
|
2013-10-05 06:14:35 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-10 22:57:04 +01:00
|
|
|
|
2013-10-05 06:14:35 +02:00
|
|
|
bool logLevel(LEVELS log_level)
|
|
|
|
{
|
|
|
|
#ifdef G2_DYNAMIC_LOGGING
|
|
|
|
int level = log_level.value;
|
|
|
|
CHECK((level >= DEBUG.value) && (level <= FATAL.value));
|
2014-01-09 06:48:18 +01:00
|
|
|
bool status = (internal::g_log_level_status[level].load(std::memory_order_acquire));
|
2013-10-05 06:14:35 +02:00
|
|
|
return status;
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // g2
|