WPILibC++  2019.2.1-23-g997d4fd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Logger Functions

Typedefs

typedef std::function< void(unsigned
int level, const char *file,
unsigned int line, const char
*msg)> 
nt::LogFunc
 Log function. More...
 

Functions

void nt::SetLogger (LogFunc func, unsigned int min_level)
 Set logger callback function. More...
 
NT_Logger nt::AddLogger (NT_Inst inst, std::function< void(const LogMessage &msg)> func, unsigned int min_level, unsigned int max_level)
 Add logger callback function. More...
 
NT_LoggerPoller nt::CreateLoggerPoller (NT_Inst inst)
 Create a log poller. More...
 
void nt::DestroyLoggerPoller (NT_LoggerPoller poller)
 Destroy a log poller. More...
 
NT_Logger nt::AddPolledLogger (NT_LoggerPoller poller, unsigned int min_level, unsigned int max_level)
 Set the log level for a log poller. More...
 
std::vector< LogMessage > nt::PollLogger (NT_LoggerPoller poller)
 Get the next log event. More...
 
std::vector< LogMessage > nt::PollLogger (NT_LoggerPoller poller, double timeout, bool *timed_out)
 Get the next log event. More...
 
void nt::CancelPollLogger (NT_LoggerPoller poller)
 Cancel a PollLogger call. More...
 
void nt::RemoveLogger (NT_Logger logger)
 Remove a logger. More...
 
bool nt::WaitForLoggerQueue (NT_Inst inst, double timeout)
 Wait for the incoming log event queue to be empty. More...
 

Detailed Description

Typedef Documentation

typedef std::function<void(unsigned int level, const char* file, unsigned int line, const char* msg)> nt::LogFunc

Log function.

Parameters
levellog level of the message (see NT_LogLevel)
fileorigin source filename
lineorigin source line number
msgmessage

Function Documentation

NT_Logger nt::AddLogger ( NT_Inst  inst,
std::function< void(const LogMessage &msg)>  func,
unsigned int  min_level,
unsigned int  max_level 
)

Add logger callback function.

By default, log messages are sent to stderr; this function sends log messages to the provided callback function instead. The callback function will only be called for log messages with level greater than or equal to min_level and less than or equal to max_level; messages outside this range will be silently ignored.

Parameters
instinstance handle
funclog callback function
min_levelminimum log level
max_levelmaximum log level
Returns
Logger handle
NT_Logger nt::AddPolledLogger ( NT_LoggerPoller  poller,
unsigned int  min_level,
unsigned int  max_level 
)

Set the log level for a log poller.

Events will only be generated for log messages with level greater than or equal to min_level and less than or equal to max_level; messages outside this range will be silently ignored.

Parameters
pollerpoller handle
min_levelminimum log level
max_levelmaximum log level
Returns
Logger handle
void nt::CancelPollLogger ( NT_LoggerPoller  poller)

Cancel a PollLogger call.

This wakes up a call to PollLogger for this poller and causes it to immediately return an empty array.

Parameters
pollerpoller handle
NT_LoggerPoller nt::CreateLoggerPoller ( NT_Inst  inst)

Create a log poller.

A poller provides a single queue of poll events. The returned handle must be destroyed with DestroyLoggerPoller().

Parameters
instinstance handle
Returns
poller handle
void nt::DestroyLoggerPoller ( NT_LoggerPoller  poller)

Destroy a log poller.

This will abort any blocked polling call and prevent additional events from being generated for this poller.

Parameters
pollerpoller handle
std::vector<LogMessage> nt::PollLogger ( NT_LoggerPoller  poller)

Get the next log event.

This blocks until the next log occurs.

Parameters
pollerpoller handle
Returns
Information on the log events. Only returns empty if an error occurred (e.g. the instance was invalid or is shutting down).
std::vector<LogMessage> nt::PollLogger ( NT_LoggerPoller  poller,
double  timeout,
bool *  timed_out 
)

Get the next log event.

This blocks until the next log occurs or it times out.

Parameters
pollerpoller handle
timeouttimeout, in seconds
timed_outtrue if the timeout period elapsed (output)
Returns
Information on the log events. If empty is returned and timed_out is also false, an error occurred (e.g. the instance was invalid or is shutting down).
void nt::RemoveLogger ( NT_Logger  logger)

Remove a logger.

Parameters
loggerLogger handle to remove
void nt::SetLogger ( LogFunc  func,
unsigned int  min_level 
)

Set logger callback function.

By default, log messages are sent to stderr; this function changes the log level and sends log messages to the provided callback function instead. The callback function will only be called for log messages with level greater than or equal to min_level; messages lower than this level will be silently ignored.

Parameters
funclog callback function
min_levelminimum log level
bool nt::WaitForLoggerQueue ( NT_Inst  inst,
double  timeout 
)

Wait for the incoming log event queue to be empty.

This is primarily useful for deterministic testing. This blocks until either the log event queue is empty (e.g. there are no more events that need to be passed along to callbacks or poll queues) or the timeout expires.

Parameters
instinstance handle
timeouttimeout, in seconds. Set to 0 for non-blocking behavior, or a negative value to block indefinitely
Returns
False if timed out, otherwise true.