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

#include <debug.h>

Collaboration diagram for Log_output:
Collaboration graph

Classes

class  Buffer
 

Public Member Functions

 Log_output ()
 
 Log_output (const Log_output &)=delete
 
 Log_output (Log_output &&)=delete
 
Buffer get_buffer ()
 
const std::string & get_level_style (int lvl)
 
bool get_skip_repeats () const
 
bool is_interactive () const
 
Log_output & operator= (const Log_output &)=delete
 
Log_output & operator= (Log_output &&)=delete
 
void set_skip_repeats (bool val)
 
void set_timestamp_mode (log_timestamp_mode val)
 

Private Member Functions

std::string & get_internal_buffer ()
 
void submit ()
 
void submit_raw ()
 

Private Attributes

bool interactive = false
 
std::string last_msg
 
int last_msg_repeats = 0
 
std::mutex mut
 
log_timestamp_mode show_timestamps
 
std::atomic< bool > skip_repeated = true
 

Static Private Attributes

static constexpr int initial_buf_size = 256
 

Friends

class Buffer
 

Detailed Description

Definition at line 125 of file debug.h.

Constructor & Destructor Documentation

◆ Log_output() [1/3]

Log_output::Log_output ( )

Definition at line 396 of file debug.cpp.

396 {
397 last_msg.reserve(initial_buf_size);
399}
static constexpr int initial_buf_size
Definition debug.h:173
std::string last_msg
Definition debug.h:188
bool interactive
Definition debug.h:182
bool color_output_init()
sets internal variable color_stdout and retunrs its contents

References color_output_init(), initial_buf_size, interactive, and last_msg.

Here is the call graph for this function:

◆ Log_output() [2/3]

Log_output::Log_output ( const Log_output & )
delete

◆ Log_output() [3/3]

Log_output::Log_output ( Log_output && )
delete

Member Function Documentation

◆ get_buffer()

Buffer Log_output::get_buffer ( )
inline

Definition at line 153 of file debug.h.

153{ return Buffer(*this); }
friend class Buffer
Definition debug.h:191

References Buffer.

Referenced by Logger::~Logger(), color_printf(), and log_vprintf().

◆ get_internal_buffer()

std::string & Log_output::get_internal_buffer ( )
inlineprivate

Definition at line 174 of file debug.h.

174 {
175 thread_local static std::string buffer(initial_buf_size, '\0');
176 return buffer;
177 }

References initial_buf_size.

Referenced by Log_output::Buffer::Buffer(), Log_output::Buffer::get(), submit(), and submit_raw().

◆ get_level_style()

const std::string & Log_output::get_level_style ( int lvl)
inline

Definition at line 194 of file debug.h.

194 {
195 static std::string empty = "";
196
197 if (!is_interactive()) {
198 return empty;
199 }
200
201 switch(lvl){
202 case LOG_LEVEL_FATAL: {
203 static std::string style = TERM_BOLD TERM_FG_RED;
204 return style;
205 }
206 case LOG_LEVEL_ERROR: {
207 static std::string style = TERM_FG_RED;
208 return style;
209 }
210 case LOG_LEVEL_WARNING: {
211 static std::string style = TERM_FG_YELLOW;
212 return style;
213 }
214 case LOG_LEVEL_NOTICE: {
215 static std::string style = TERM_FG_GREEN;
216 return style;
217 }
218 default:
219 return empty;
220 }
221}
bool is_interactive() const
Definition debug.h:161
#define TERM_BOLD
Definition color_out.h:48
#define TERM_FG_YELLOW
Definition color_out.h:52
#define TERM_FG_GREEN
Definition color_out.h:51
#define TERM_FG_RED
Definition color_out.h:50
#define LOG_LEVEL_NOTICE
information that may be interesting
Definition debug.h:61
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
#define LOG_LEVEL_FATAL
errors that prevent UG run
Definition debug.h:58
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60

References is_interactive(), LOG_LEVEL_ERROR, LOG_LEVEL_FATAL, LOG_LEVEL_NOTICE, LOG_LEVEL_WARNING, TERM_BOLD, TERM_FG_GREEN, TERM_FG_RED, and TERM_FG_YELLOW.

Referenced by Logger::Logger(), and log_vprintf().

Here is the call graph for this function:

◆ get_skip_repeats()

bool Log_output::get_skip_repeats ( ) const
inline

Definition at line 156 of file debug.h.

156{ return skip_repeated.load(std::memory_order_relaxed); }
std::atomic< bool > skip_repeated
Definition debug.h:179

References skip_repeated.

Referenced by keyboard_control::impl::run().

◆ is_interactive()

bool Log_output::is_interactive ( ) const
inline

Definition at line 161 of file debug.h.

161{ return interactive; }

References interactive.

Referenced by get_level_style().

◆ operator=() [1/2]

Log_output & Log_output::operator= ( const Log_output & )
delete

◆ operator=() [2/2]

Log_output & Log_output::operator= ( Log_output && )
delete

◆ set_skip_repeats()

void Log_output::set_skip_repeats ( bool val)
inline

Definition at line 155 of file debug.h.

155{ skip_repeated.store(val, std::memory_order_relaxed); }
int void * val

References skip_repeated, and val.

Referenced by parse_opts_set_logging(), and keyboard_control::impl::run().

◆ set_timestamp_mode()

void Log_output::set_timestamp_mode ( log_timestamp_mode val)
inline

Definition at line 158 of file debug.h.

158{ show_timestamps = val; }
log_timestamp_mode show_timestamps
Definition debug.h:180

References show_timestamps, and val.

Referenced by parse_opts_set_logging().

◆ submit()

void Log_output::submit ( )
inlineprivate

Definition at line 223 of file debug.h.

223 {
224 static constexpr int ts_bufsize = 32; //log10(2^64) is 19.3, so should be enough
225 char ts_str[ts_bufsize];
226 ts_str[0] = '\0';
227
230 {
231 const time_ns_t time_ns = get_time_in_ns();
232 snprintf(ts_str, ts_bufsize, "[%.3f] ",
233 (double) time_ns / NS_IN_SEC_DBL);
234 }
235
236 const char *start_newline = "";
237 std::lock_guard<std::mutex> lock(mut);
238 if (skip_repeated && interactive) {
239 if (get_internal_buffer() == last_msg) {
241 printf(" Last message repeated %d times\r", last_msg_repeats);
242 fflush(stdout);
243 return;
244 }
245
246 if (last_msg_repeats > 0) {
247 start_newline = "\n";
248 }
250 }
251
252 printf("%s%s%s", start_newline, ts_str, get_internal_buffer().c_str());
253
254 std::swap(last_msg, get_internal_buffer());
255}
int last_msg_repeats
Definition debug.h:189
std::string & get_internal_buffer()
Definition debug.h:174
std::mutex mut
Definition debug.h:187
volatile int log_level
Definition debug.cpp:65
#define LOG_LEVEL_VERBOSE
Definition debug.h:63
@ LOG_TIMESTAMP_AUTO
Definition debug.h:75
@ LOG_TIMESTAMP_ENABLED
Definition debug.h:74
long long time_ns_t
Definition tv.h:81
#define NS_IN_SEC_DBL
Definition tv.h:93
static time_ns_t get_time_in_ns()
Definition tv.h:101

References get_internal_buffer(), get_time_in_ns(), interactive, last_msg, last_msg_repeats, log_level, LOG_LEVEL_VERBOSE, LOG_TIMESTAMP_AUTO, LOG_TIMESTAMP_ENABLED, mut, NS_IN_SEC_DBL, show_timestamps, and skip_repeated.

Referenced by Log_output::Buffer::submit().

Here is the call graph for this function:

◆ submit_raw()

void Log_output::submit_raw ( )
inlineprivate

Definition at line 257 of file debug.h.

257 {
258 std::lock_guard<std::mutex> lock(mut);
259 if(last_msg_repeats > 0)
260 fputc('\n', stdout);
261 fputs(get_internal_buffer().c_str(), stdout);
262 std::swap(last_msg, get_internal_buffer());
264}

References get_internal_buffer(), last_msg, last_msg_repeats, and mut.

Referenced by Log_output::Buffer::submit_raw().

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ Buffer

friend class Buffer
friend

Definition at line 191 of file debug.h.

Referenced by get_buffer().

Member Data Documentation

◆ initial_buf_size

int Log_output::initial_buf_size = 256
staticconstexprprivate

Definition at line 173 of file debug.h.

Referenced by Log_output(), and get_internal_buffer().

◆ interactive

bool Log_output::interactive = false
private

Definition at line 182 of file debug.h.

Referenced by Log_output(), is_interactive(), and submit().

◆ last_msg

std::string Log_output::last_msg
private

Definition at line 188 of file debug.h.

Referenced by Log_output(), submit(), and submit_raw().

◆ last_msg_repeats

int Log_output::last_msg_repeats = 0
private

Definition at line 189 of file debug.h.

Referenced by submit(), and submit_raw().

◆ mut

std::mutex Log_output::mut
private

Definition at line 187 of file debug.h.

Referenced by submit(), and submit_raw().

◆ show_timestamps

log_timestamp_mode Log_output::show_timestamps
private

Definition at line 180 of file debug.h.

Referenced by set_timestamp_mode(), and submit().

◆ skip_repeated

std::atomic<bool> Log_output::skip_repeated = true
private

Definition at line 179 of file debug.h.

Referenced by get_skip_repeats(), set_skip_repeats(), and submit().


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