2013-10-05 06:14:35 +02:00
|
|
|
/** ==========================================================================
|
2014-03-09 07:33:49 +01: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.
|
2015-04-29 11:21:45 +02:00
|
|
|
*
|
2014-07-03 23:42:19 +02:00
|
|
|
* For more information see g3log/LICENSE or refer refer to http://unlicense.org
|
2014-03-09 07:33:49 +01:00
|
|
|
* ============================================================================
|
|
|
|
* 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
|
|
|
|
* ********************************************* */
|
2013-10-05 06:14:35 +02:00
|
|
|
|
|
|
|
#include "g2loglevels.hpp"
|
2013-12-10 22:57:04 +01:00
|
|
|
#include "g2log.hpp"
|
2013-10-05 06:14:35 +02:00
|
|
|
#include <atomic>
|
2014-01-14 07:10:26 +01:00
|
|
|
#include <cassert>
|
2015-02-02 08:31:43 +01:00
|
|
|
|
2014-03-09 07:33:49 +01:00
|
|
|
namespace g2 {
|
|
|
|
namespace internal {
|
|
|
|
bool wasFatal(const LEVELS& level) {
|
|
|
|
return level.value >= FATAL.value;
|
|
|
|
}
|
2013-10-05 06:14:35 +02:00
|
|
|
|
2014-03-09 07:33:49 +01:00
|
|
|
#ifdef G2_DYNAMIC_LOGGING
|
|
|
|
// All levels are by default ON: i.e. for DEBUG, INFO, WARNING, FATAL
|
|
|
|
const int g_level_size{FATAL.value + 1};
|
|
|
|
std::atomic<bool> g_log_level_status[4]{{true},{true},{true},{true}};
|
2015-04-29 11:21:45 +02:00
|
|
|
#endif
|
2014-03-09 07:33:49 +01:00
|
|
|
} // internal
|
2013-10-05 06:14:35 +02:00
|
|
|
|
|
|
|
#ifdef G2_DYNAMIC_LOGGING
|
2014-03-09 07:33:49 +01:00
|
|
|
void setLogLevel(LEVELS log_level, bool enabled) {
|
|
|
|
assert(internal::g_level_size == 4 && "Mismatch between number of logging levels and their use");
|
|
|
|
int level = log_level.value;
|
2015-02-02 08:31:43 +01:00
|
|
|
CHECK((level >= g2::kDebugVaulue) && (level <= FATAL.value));
|
2014-03-09 07:33:49 +01:00
|
|
|
internal::g_log_level_status[level].store(enabled, std::memory_order_release);
|
|
|
|
}
|
2013-10-05 06:14:35 +02:00
|
|
|
#endif
|
|
|
|
|
2014-03-09 07:33:49 +01:00
|
|
|
bool logLevel(LEVELS log_level) {
|
2013-10-05 06:14:35 +02:00
|
|
|
#ifdef G2_DYNAMIC_LOGGING
|
2014-03-09 07:33:49 +01:00
|
|
|
int level = log_level.value;
|
2015-02-02 08:31:43 +01:00
|
|
|
CHECK((level >= g2::kDebugVaulue) && (level <= FATAL.value));
|
2014-03-09 07:33:49 +01:00
|
|
|
bool status = (internal::g_log_level_status[level].load(std::memory_order_acquire));
|
|
|
|
return status;
|
2013-10-05 06:14:35 +02:00
|
|
|
#endif
|
2014-03-09 07:33:49 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-10-05 06:14:35 +02:00
|
|
|
} // g2
|