33 #include <sys/syscall.h>
34#elif defined(__APPLE__) && defined(__MACH__)
39 #include <boost/python.hpp>
40namespace bp = boost::python;
54std::mutex rogue::Logging::levelMtx_;
57std::vector<rogue::LogFilter*> rogue::Logging::filters_;
66 std::vector<rogue::LogFilter*>::iterator it;
68 name_ =
"pyrogue." + name;
74 for (it = filters_.begin(); it < filters_.end(); it++) {
75 if (name_.find((*it)->name_) == 0) {
76 if ((*it)->level_ < level_) level_ = (*it)->level_;
81 if (!quiet) warning(
"Starting logger with level = %" PRIu32, level_);
97 filters_.push_back(flt);
102void rogue::Logging::intLog(uint32_t level,
const char* fmt, va_list args) {
103 if (level < level_)
return;
107 vsnprintf(buffer,
sizeof(buffer), fmt, args);
108 gettimeofday(&tme, NULL);
109 printf(
"%" PRIi64
".%06" PRIi64
":%s: %s\n",
110 static_cast<int64_t
>(tme.tv_sec),
111 static_cast<int64_t
>(tme.tv_usec),
119 intLog(level, fmt, arg);
161#if defined(__linux__)
162 tid = syscall(SYS_gettid);
163#elif defined(__APPLE__) && defined(__MACH__)
165 pthread_threadid_np(NULL, &tid64);
166 tid =
static_cast<uint32_t
>(tid64);
171 this->log(Thread,
"PID=%" PRIu32
", TID=%" PRIu32, getpid(), tid);
176 bp::class_<rogue::Logging, rogue::LoggingPtr, boost::noncopyable>(
"Logging", bp::no_init)
178 .staticmethod(
"setLevel")
180 .staticmethod(
"setFilter")
Per-logger level override filter entry.
~Logging()
Destroys the logger instance.
void info(const char *fmt,...)
Emits a formatted message at Info level.
static const uint32_t Thread
Thread-trace severity level constant.
void logThreadId()
Emits the current thread id through this logger.
static void setup_python()
Registers Python bindings for Logging.
Logging(const std::string &name, bool quiet=false)
Constructs a logger.
static std::shared_ptr< rogue::Logging > create(const std::string &name, bool quiet=false)
Creates a logger instance.
static void setFilter(const std::string &filter, uint32_t level)
Sets name-based filter level override.
void warning(const char *fmt,...)
Emits a formatted message at Warning level.
static const uint32_t Debug
Debug severity level constant.
void log(uint32_t level, const char *fmt,...)
Emits a formatted log message at a specified level.
static const uint32_t Error
Error severity level constant.
static const uint32_t Info
Informational severity level constant.
static const uint32_t Warning
Warning severity level constant.
static void setLevel(uint32_t level)
Sets the global default logging level.
void critical(const char *fmt,...)
Emits a formatted message at Critical level.
void debug(const char *fmt,...)
Emits a formatted message at Debug level.
static const uint32_t Critical
Critical severity level constant.
void error(const char *fmt,...)
Emits a formatted message at Error level.
std::shared_ptr< rogue::Logging > LoggingPtr
Shared pointer alias for Logging.