This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.
A C++ stream-style logging interface. More...
#include <ofLog.h>

Public Member Functions | |
Logging | |
ofLog () | |
Start logging on notice level. | |
ofLog (ofLogLevel level) | |
Start logging on a specific ofLogLevel. | |
ofLog (ofLogLevel level, const std::string &message) | |
Log a string at a specific log level. | |
template<typename ... Args> | |
ofLog (ofLogLevel level, const char *format, Args &&... args) | |
Logs a message at a specific log level using the printf interface. | |
Static Public Member Functions | |
Logging configuration | |
static void | setAutoSpace (bool autoSpace) |
Let the logger automaticly add spaces between messages. | |
static void | setChannel (std::shared_ptr< ofBaseLoggerChannel > channel) |
Set the logging channel destinations for messages. | |
static std::shared_ptr< ofBaseLoggerChannel > | getChannel () |
Get the current logging channel. | |
Detailed Description
A C++ stream-style logging interface.
ofLog accepts variables via the std::ostream operator << and builds a string and logs it when the stream is finished (via the destructor). A newline is printed automatically and all the stream controls (std::endl, std::flush, std::hex, etc) work normally. The default log level is OF_LOG_NOTICE
.
Basic usage:
It also accepts the legacy ofLog interface: ofLog(ofLogLevel level, string message):
Constructor & Destructor Documentation
◆ ofLog() [1/4]
ofLog::ofLog | ( | ) |
Start logging on notice level.
ofLog provides a streaming log interface by accepting variables via the std::ostream
operator <<
similar to std::cout
and std::cerr
.
It builds a string and logs it when the stream is finished. A newline is printed automatically and all the stream controls (std::endl
, std::flush
, std::hex
, etc) work normally.
The log level is OF_LOG_NOTICE
by default.
◆ ofLog() [2/4]
ofLog::ofLog | ( | ofLogLevel | level | ) |
Start logging on a specific ofLogLevel.
Example:
You can use the derived convenience classes as an alternative for specific log levels:
ofLogVerbose() ofLogNotice() ofLogWarning() ofLogError() ofLogFatalError()
- Parameters
-
level The ofLogLevel for this log message.
◆ ofLog() [3/4]
ofLog::ofLog | ( | ofLogLevel | level, |
const std::string & | message | ||
) |
Log a string at a specific log level.
Supply the logging message as a parameter to the function instead of as a stream.
The string message can be concatenated using the ofToString(const T& value) conversion function:
- Parameters
-
level The ofLogLevel for this log message. message The log message.
◆ ofLog() [4/4]
|
inline |
Logs a message at a specific log level using the printf interface.
The message is built using the formatting from the C printf function and can be used as a direct replacement. Essentially, the second argument is a string with special formatting specifiers starting with '' that specify where the following variables go in the message. You can have as many variables as you want following the logLevel and format string, but there must be a % specifier for each subsequent variable.
For quick reference, here are a few of the most useful formatting specifiers:
d
: integer number,123
f
: floating point number,123.45
s
: a C string (null terminated); this is not a C++ string, use string::c_str() to get a C string from a C++ stringc
: a single characterx
: unsigned integer as a hexidecimal number;x
uses lower-case letters andX
uses upper-case%%
: prints a%
character
The specifier should match the variable type as it is used to tell the function how to convert that primitive type (int, float, character, etc) into a string.
For instance, let's say we want to print two messages, a salutation and the value of an int, a float, and a string variable:
Note: theNames.c_str()
returns a C string from theNames which is a C++ string object.
There are other formatting options such as setting the decimal precision of float objects and the forward padding of numbers (i.e. 0001 instead of 1). See the Wikipedia printf format string article for more detailed information.
- Parameters
-
level The ofLogLevel for this log message. format The printf-style format string.
Member Function Documentation
◆ getChannel()
|
static |
Get the current logging channel.
◆ setAutoSpace()
|
static |
Let the logger automaticly add spaces between messages.
Default is false
.
- Parameters
-
autoSpace Set to true to add spaces between messages
◆ setChannel()
|
static |
Set the logging channel destinations for messages.
This can be used to output to files instead of stdout.
- See also
- ofFileLoggerChannel ofConsoleLoggerChannel
- Parameters
-
channel The channel to log to.
The documentation for this class was generated from the following files: