forked from pEp.foundation/libpEpAdapter
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
993 B
C++
44 lines
993 B
C++
// This file is under GNU General Public License 3.0
|
|
// see LICENSE.txt
|
|
|
|
#include "pEpLog.hh"
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <mutex>
|
|
#include <atomic>
|
|
|
|
|
|
namespace pEp {
|
|
namespace Adapter {
|
|
namespace pEpLog {
|
|
|
|
std::mutex mtx;
|
|
|
|
std::atomic_bool is_enabled{false};
|
|
|
|
void set_enabled(bool enabled)
|
|
{
|
|
is_enabled.store(enabled);
|
|
}
|
|
|
|
bool get_enabled()
|
|
{
|
|
return is_enabled.load();
|
|
}
|
|
|
|
void log(std::string msg)
|
|
{
|
|
if (is_enabled.load()) {
|
|
std::lock_guard<std::mutex> l(mtx);
|
|
#ifdef ANDROID
|
|
__android_log_print(ANDROID_LOG_DEBUG, "pEpDebugLog", "%s", msg.c_str());
|
|
#else
|
|
std::cout << msg << std::endl; //std::endl also flushes
|
|
#endif
|
|
}
|
|
}
|
|
|
|
} // namespace pEpLog
|
|
} // namespace Adapter
|
|
} // namespace pEp
|