UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
Logger Class Reference

#include <debug.h>

Collaboration diagram for Logger:
Collaboration graph

Public Member Functions

 Logger (int l)
 
 ~Logger ()
 
std::ostream & Get ()
 

Private Attributes

int level
 
std::ostringstream oss
 

Friends

void log_msg_once (int level, uint32_t id, const char *msg,...)
 

Detailed Description

Definition at line 272 of file debug.h.

Constructor & Destructor Documentation

◆ Logger()

Logger::Logger ( int l)
inline

Definition at line 275 of file debug.h.

275 : level(l) {
277 }
const std::string & get_level_style(int lvl)
Definition debug.h:194
std::ostringstream oss
Definition debug.h:308
int level
Definition debug.h:307
Log_output & get_log_output()
Definition debug.h:266

References Log_output::get_level_style(), get_log_output(), level, and oss.

Here is the call graph for this function:

◆ ~Logger()

Logger::~Logger ( )
inline

Definition at line 279 of file debug.h.

279 {
280 std::string msg = oss.str();
281
282 if (get_log_output().is_interactive()) {
283 // add TERM_RESET (before NL if present at the end)
284 const bool eol_nl =
285 msg.size() > 0 && msg.at(msg.size() - 1) == '\n';
286 if (eol_nl) {
287 msg.resize(msg.size() - 1);
288 }
289 msg += TERM_RESET;
290 if (eol_nl) {
291 msg += "\n";
292 }
293 } else {
295 }
296
297 auto buf = get_log_output().get_buffer();
298 buf.append(msg);
299 buf.submit();
300 }
void append(std::string_view sv)
Definition debug.h:130
Buffer get_buffer()
Definition debug.h:153
string prune_ansi_sequences_str(const char *in)
#define TERM_RESET
Definition color_out.h:47

References Log_output::Buffer::append(), Log_output::get_buffer(), get_log_output(), oss, prune_ansi_sequences_str(), and TERM_RESET.

Here is the call graph for this function:

Member Function Documentation

◆ Get()

std::ostream & Logger::Get ( )
inline

Definition at line 302 of file debug.h.

302 {
303 return oss;
304 }

References oss.

Friends And Related Symbol Documentation

◆ log_msg_once

void log_msg_once ( int level,
uint32_t id,
const char * msg,
... )
friend

Definition at line 137 of file debug.cpp.

137 {
138 if (log_level < level) {
139 return;
140 }
141 static volatile uint32_t oneshot_messages[10];
142 static atomic<size_t> oneshot_messages_cnt;
143 for (size_t i = 0; i < oneshot_messages_cnt; ++i) {
144 if (oneshot_messages[i] == id) {
145 return;
146 }
147 }
148
149 va_list aq;
150 va_start(aq, msg);
151 log_vprintf(level, msg, aq);
152 va_end(aq);
153
154 size_t last_cnt = oneshot_messages_cnt.fetch_add(1);
155 if (last_cnt < sizeof oneshot_messages / sizeof oneshot_messages[0]) {
156 oneshot_messages[last_cnt] = id;
157 } else {
158 log_msg(LOG_LEVEL_WARNING, "oneshot_messages full!\n");
159 }
160}
static void log_vprintf(int level, const char *format, va_list ap)
Definition debug.cpp:91
volatile int log_level
Definition debug.cpp:65
void log_msg(int log_level, const char *format,...) __attribute__((format(printf
Definition debug.cpp:130
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60

Member Data Documentation

◆ level

int Logger::level
private

Definition at line 307 of file debug.h.

Referenced by Logger().

◆ oss

std::ostringstream Logger::oss
private

Definition at line 308 of file debug.h.

Referenced by Logger(), ~Logger(), and Get().


The documentation for this class was generated from the following file: