Turi Create  4.0
file_logger Class Reference

#include <core/logging/logger.hpp>

Public Member Functions

 file_logger ()
 
bool set_log_file (std::string file)
 destructor. flushes and closes the current logger file More...
 
void set_log_to_console (bool consolelog, bool _log_to_stderr=false)
 
void set_pid (size_t pid)
 
size_t get_pid () const
 
std::string get_log_file (void)
 Returns the current logger file.
 
bool get_log_to_console ()
 Returns true if output is being written to stderr.
 
int get_log_level ()
 Returns the current logger level.
 
void add_observer (int loglevel, std::function< void(int lineloglevel, const char *buf, size_t len)> callback_fn)
 
std::function< void(int lineloglevel, const char *buf, size_t len)> get_observer (int loglevel)
 
template<typename T >
file_loggeroperator<< (T a)
 
file_loggeroperator<< (const char *a)
 
file_loggeroperator<< (std::ostream &(*f)(std::ostream &))
 
void set_log_level (int new_log_level)
 
void _log (int loglevel, const char *file, const char *function, size_t line, const char *fmt, va_list arg)
 

Detailed Description

The main logging class.

This writes to a file, and/or the system console. The main logger global_logger is a global instance of this class.

Definition at line 474 of file logger.hpp.

Constructor & Destructor Documentation

◆ file_logger()

file_logger::file_logger ( )

Default constructor. By default, log_to_console is on, there is no logger file, and logger level is set to LOG_EMPH

Member Function Documentation

◆ _log()

void file_logger::_log ( int  loglevel,
const char *  file,
const char *  function,
size_t  line,
const char *  fmt,
va_list  arg 
)

logs the message if loglevel>=OUTPUTLEVEL This function should not be used directly. Use logger()

Parameters
loglevelType of message
See also
LOG_DEBUG LOG_INFO LOG_WARNING LOG_ERROR LOG_FATAL
Parameters
fileFile where the logger call originated
functionFunction where the logger call originated
lineLine number where the logger call originated
fmtprintf format string
argvar args. The parameters that match the format string

◆ add_observer()

void file_logger::add_observer ( int  loglevel,
std::function< void(int lineloglevel, const char *buf, size_t len)>  callback_fn 
)
inline

Set a callback to be called whenever a log message at a particular log level is issued. Only one observer can be set per log level.

Definition at line 532 of file logger.hpp.

◆ get_observer()

std::function<void(int lineloglevel, const char* buf, size_t len)> file_logger::get_observer ( int  loglevel)
inline

Gets the callback called when a log message at a particular log level is issued. Note that only one observer can be set per log level.

Definition at line 545 of file logger.hpp.

◆ get_pid()

size_t file_logger::get_pid ( ) const
inline

If consolelog is true, subsequent logger output will be written to stdout / stderr. If log_to_stderr is true, all output is logged to stderr.

Definition at line 509 of file logger.hpp.

◆ operator<<() [1/3]

template<typename T >
file_logger& file_logger::operator<< ( a)
inline

Streams a value into the logger.

Definition at line 555 of file logger.hpp.

◆ operator<<() [2/3]

file_logger& file_logger::operator<< ( const char *  a)
inline

Streams a value into the logger.

Definition at line 573 of file logger.hpp.

◆ operator<<() [3/3]

file_logger& file_logger::operator<< ( std::ostream &(*)(std::ostream &)  f)
inline

Streams an std::endl into the logger.

Definition at line 595 of file logger.hpp.

◆ set_log_file()

bool file_logger::set_log_file ( std::string  file)

destructor. flushes and closes the current logger file

Closes the current logger file if one exists. if 'file' is not an empty string, it will be opened and all subsequent logger output will be written into 'file'. Any existing content of 'file' will be cleared. Return true on success and false on failure.

◆ set_log_level()

void file_logger::set_log_level ( int  new_log_level)
inline

Sets the current logger level. All logging commands below the current logger level will not be written.

Definition at line 625 of file logger.hpp.

◆ set_log_to_console()

void file_logger::set_log_to_console ( bool  consolelog,
bool  _log_to_stderr = false 
)
inline

If consolelog is true, subsequent logger output will be written to stdout / stderr. If log_to_stderr is true, all output is logged to stderr.

Definition at line 494 of file logger.hpp.

◆ set_pid()

void file_logger::set_pid ( size_t  pid)
inline

If consolelog is true, subsequent logger output will be written to stdout / stderr. If log_to_stderr is true, all output is logged to stderr.

Definition at line 502 of file logger.hpp.


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