ofLogfile
ofLog provides an interface for writing text output from your app. It's basically a more useful version of std::cout
or printf
where the output can be filtered and written to the console a file, or even a custom logging module.
Sometimes you want to be able to see when something has happened inside the code, but don't need to draw something visually. Oftentimes it's more then enough to print out the state of a few variables when debugging. Other times you need to know if a crash happened while your app was running somewhere, so you log messages and variables to a file you can read after the program crashes.
Log Levels
You can set the logging level so only messages above a certain level are shown. This is useful if you want see lots of messages when debugging, but then set a higher level so only warnings and errors appear for users.
See ofSetLogLevel(ofLogLevel level) for more details.
Usage
There are 2 ways you can use ofLog:
Functional: as a function taking a message
Stream: as a stream using the << stream operator
Note: The log level specific stream objects also take a string argument for the "module". A module is a string that is added to the beginning of the log line and can be used to separate logging messages by setting an independent log level for that module only. This module-specific log level has no effect on other modules.
See ofSetLogLevel(string module, ofLogLevel level) for more details.
Example of logging to a specific module:
Warning: It is important to understand that the log level specific stream objects take the module name as an argument and the log messages via the << operator. Putting your message as a string argument inside the parentheses uses that message as a module and so nothing will be printed:
Log Message Redirection
It's useful to be able to record log messages to a file or send them to a custom destination.
For log redirection see
Global logging level
Global logger channel
ofLogclass
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):
Logging
Logging configuration
ofLogVerboseclass
Derived log class for easy verbose logging.
Example: ofLogVerbose("Log message")
.
Logging configuration
Functions
ofLogNoticeclass
Derived log class for easy notice logging.
Example: ofLogNotice("Log message")
.
Logging configuration
Functions
ofLogWarningclass
Derived log class for easy warning logging.
Example: ofLogWarning("Log message")
.
Logging configuration
Functions
ofLogErrorclass
Derived log class for easy error logging.
Example: ofLogError("Log message")
.
Logging configuration
Functions
ofLogFatalErrorclass
Derived log class for easy fatal error logging.
Example: ofLogFatalError("Log message")
.