Turi Create  4.0
Logging Statements

Global Logging Statements. More...

Macros

#define logger(lvl, fmt, ...)
 
#define logstream(lvl)
 
#define logger_once(lvl, fmt, ...)
 
#define logstream_once(lvl)
 
#define logger_ontick(sec, lvl, fmt, ...)
 
#define logstream_ontick(sec, lvl)
 
#define logprogress(fmt, ...)   logger(LOG_PROGRESS, fmt, ##__VA_ARGS__)
 
#define logprogress_stream   logstream(LOG_PROGRESS)
 
#define logprogress_ontick(sec, fmt, ...)   logger_ontick(sec, LOG_PROGRESS, fmt, ##__VA_ARGS__)
 
#define logprogress_stream_ontick(sec)   logstream_ontick(sec, LOG_PROGRESS)
 

Detailed Description

Global Logging Statements.

Macro Definition Documentation

◆ logger

#define logger (   lvl,
  fmt,
  ... 
)
Value:
(log_dispatch<(lvl >= OUTPUTLEVEL)>::exec(lvl, __FILE__, __func__, __LINE__, \
fmt, ##__VA_ARGS__))
#define OUTPUTLEVEL
Definition: logger.hpp:113

Emits a log line output in printf format at a particular log level. lvl must be one of the log levels from LOG_DEBUG to LOG_FATAL. Emitting a LOG_FATAL will kill the process.

Example:

logger(LOG_INFO, "hello world: %d", 10);

Definition at line 268 of file logger.hpp.

◆ logger_once

#define logger_once (   lvl,
  fmt,
  ... 
)
Value:
{ \
static bool __printed__ = false; \
if (!__printed__) { \
__printed__ = true; \
lvl, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)); \
} \
}
#define OUTPUTLEVEL
Definition: logger.hpp:113

Emits a log line output in printf format at a particular log level, only the first time the line is encountered. lvl must be one of the log levels from LOG_DEBUG to LOG_FATAL. Emitting a LOG_FATAL will kill the process.

Example:

logger_once(LOG_INFO, "Class %s constructed", str);

Definition at line 281 of file logger.hpp.

◆ logger_ontick

#define logger_ontick (   sec,
  lvl,
  fmt,
  ... 
)
Value:
{ \
static float last_print = -sec - 1; \
float curtime = turi::timer::approx_time_seconds(); \
if (last_print + sec <= curtime) { \
last_print = curtime; \
lvl, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__)); \
} \
}
static float approx_time_seconds()
Returns the time since program start.
#define OUTPUTLEVEL
Definition: logger.hpp:113

Emits a log line output in printf format at a particular log level, but will only print approximately once every "sec" seconds. lvl must be one of the log levels from LOG_DEBUG to LOG_FATAL. Emitting a LOG_FATAL will kill the process.

Example:

// only print once every 5 seconds
logger_ontick(5, LOG_INFO, "Class %s constructed", str);

Definition at line 300 of file logger.hpp.

◆ logprogress

#define logprogress (   fmt,
  ... 
)    logger(LOG_PROGRESS, fmt, ##__VA_ARGS__)

Emits a progress message using printf format.

Example:

logprogress("hello world: %d", 10);

Definition at line 324 of file logger.hpp.

◆ logprogress_ontick

#define logprogress_ontick (   sec,
  fmt,
  ... 
)    logger_ontick(sec, LOG_PROGRESS, fmt, ##__VA_ARGS__)

Emits a progress message using printf format, but will only print approximately once every "sec" seconds. Example:

// only print once every 5 seconds
logprogress_ontick(5, "Class %s constructed", str);

Definition at line 327 of file logger.hpp.

◆ logprogress_stream

#define logprogress_stream   logstream(LOG_PROGRESS)

Emits a progress message using a stream. The stream must terminate with a "\n" or std::endl at the end of the message.

Example:

logprogress_stream << "hello world " << 10 << std::endl;

Definition at line 325 of file logger.hpp.

◆ logprogress_stream_ontick

#define logprogress_stream_ontick (   sec)    logstream_ontick(sec, LOG_PROGRESS)

Emits a progress message using a stream. The stream must terminate with a "\n" or std::endl at the end of the message. This will only print approximately once every "sec" seconds. The stream must terminate with a "\n" or std::endl at the end of the message.

Example:

logprogress_stream_ontick(5) << "Class " << str << " constructed"
<< std::endl;

Definition at line 328 of file logger.hpp.

◆ logstream

#define logstream (   lvl)
Value:
if (lvl >= global_logger().get_log_level()) \
(log_stream_dispatch<(lvl >= OUTPUTLEVEL)>::exec(lvl, __FILE__, __func__, \
__LINE__))
#define OUTPUTLEVEL
Definition: logger.hpp:113
file_logger & global_logger()

An output stream for specified log level. lvl must be one of the log levels from LOG_DEBUG to LOG_FATAL. Emitting a LOG_FATAL will kill the process. The stream must terminate with a "\n" or std::endl at the end of the message.

Example:

logstream(LOG_INFO << "hello world: " << 10 << std::endl;

Definition at line 276 of file logger.hpp.

◆ logstream_once

#define logstream_once (   lvl)
Value:
(*({ \
static bool __printed__ = false; \
bool __prev_printed__ = __printed__; \
if (!__printed__) __printed__ = true; \
&(log_stream_dispatch<(lvl >= OUTPUTLEVEL)>::exec( \
lvl, __FILE__, __func__, __LINE__, !__prev_printed__)); \
}))
#define OUTPUTLEVEL
Definition: logger.hpp:113

An output stream for specified log level. This will only output the first time the line is encountered. lvl must be one of the log levels from LOG_DEBUG to LOG_FATAL. Emitting a LOG_FATAL will kill the process. The stream must terminate with a "\n" or std::endl at the end of the message.

Example:

logstream_once(LOG_INFO) << "Class " << str << " constructed" << std::endl;

Definition at line 291 of file logger.hpp.

◆ logstream_ontick

#define logstream_ontick (   sec,
  lvl 
)
Value:
(*({ \
static float last_print = -sec - 1; \
float curtime = turi::timer::approx_time_seconds(); \
bool print_now = false; \
if (last_print + sec <= curtime) { \
last_print = curtime; \
print_now = true; \
} \
&(log_stream_dispatch<(lvl >= OUTPUTLEVEL)>::exec(lvl, __FILE__, __func__, \
__LINE__, print_now)); \
}))
static float approx_time_seconds()
Returns the time since program start.
#define OUTPUTLEVEL
Definition: logger.hpp:113

An output stream for specified log level. This will only print approximately once every "sec" seconds. lvl must be one of the log levels from LOG_DEBUG to LOG_FATAL. Emitting a LOG_FATAL will kill the process. The stream must terminate with a "\n" or std::endl at the end of the message.

Example:

logstream_ontick(5, LOG_INFO) << "Class " << str << " constructed"
<< std::endl;

Definition at line 311 of file logger.hpp.