ofLog (functions)
ofGetLogLevel( )
ofLogLevel ofGetLogLevel()Get the currently set global logging level.
Returns: The currently set global logging level.
Get the current log level. This is useful when combined with ofGetLogLevelName() if you want to print the current log level:
ofLogLevel currentLevel = ofGetLogLevel();
ofLog() << "The current log level is " << ofGetLogLevelName(currentLevel);
ofGetLogLevel( ... )
ofLogLevel ofGetLogLevel(string module)Get the logging level for a specific module.
Parameters:
module specific module name.
Returns: The currently set specific module logging level.
ofGetLogLevelName( ... )
string ofGetLogLevelName(ofLogLevel level, bool pad=false)Get log level name as a string.
Parameters:
level The ofLogLevel you want as a string.
pad True if you want all log level names to be the same length.
Returns: The log level name as a string.
ofLogToConsole( )
void ofLogToConsole()Set the logging to ouptut to the console.
This is the default state and can be called to reset console logging after ofLogToFile or ofSetLoggerChannel has been called.
ofLogToFile( ... )
void ofLogToFile(const filesystem::path &path, bool append=false)Set the logging to output to a file instead of the console.
Parameters:
path The path to the log file to use.
append True if you want to append to the existing file.
Enable logging to a file instead of the console. Set the path and name of the log file and it will be created if it doesn't exist. If it does exist, it will be overwritten unless you set append to true, whereas new lines will be added to the bottom of the file.
// logs to the console
ofLog() << "a test string";
// enable file logging, append text
// the log file will be created in the data directory
ofLogToFile("myLogFile.txt", true);
// now logs to the file
ofLog() << "a test string";
Note: When file logging is enabled, will not see log messages on the console!
ofSetLogLevel( ... )
void ofSetLogLevel(ofLogLevel level)Sets the logging level to selectively show log messages.
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.
ofLogLevel values in order from lowest to highest level are:
OF_LOG_VERBOSE(lowest level)OF_LOG_NOTICEOF_LOG_WARNINGOF_LOG_ERROROF_LOG_FATAL_ERROROF_LOG_SILENT(highest level)
Thus, setting a log level of OF_LOG_ERROR, means only logging messages
marked OF_LOG_ERROR and OF_LOG_FATAL_ERROR will be printed. Conversely,
setting OF_LOG_VERBOSE means all log level messages, including
OF_LOG_VERBOSE, will be printed. Finally, setting a log level of
OF_LOG_SILENT will prevent any messages from being printed.
The default ofLogLevel is OF_LOG_NOTICE.
Parameters:
level the ofLogLevel (and below) you want to show
Sets the logging level so only messages above a certain priority 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. logLevel values are (in order of priority): OF_LOG_VERBOSE OF_LOG_NOTICE OF_LOG_WARNING OF_LOG_ERROR OF_LOG_FATAL_ERROR OF_LOG_SILENT Following priority, setting a log level of OF_LOG_ERROR, means only error & fatal error messages will be printed. Conversely, setting OF_LOG_VERBOSE means all log level messages will be printed. Here's a code example:
// set to warning level
ofSetLogLevel(OF_LOG_WARNING);
ofLogWarning() << "a warning print"; // this prints
ofLogNotice() << "test print"; // this doesn't
ofLogVerbose() << "a verbose print"; // this doesn't either
// set to notice level
ofSetLogLevel(OF_LOG_NOTICE);
ofLogWarning() << "a warning print"; // this still prints
ofLogNotice() << "test print"; // this does too
ofLogVerbose() << "a verbose print"; // this doesn't
The default log level is OF_LOG_NOTICE. OF_LOG_SILENT is a special value which disables all messages.
ofSetLogLevel( ... )
void ofSetLogLevel(string module, ofLogLevel level)Set the logging level for a specific module.
When a module name is supplied to ofSetLogLevel, the provided ofLogLevel is selectively applied only to ofLog messages marked with the specified module.
This is particularly useful when the user desires to, for example, log at an OF_LOG_VERBOSE level for one module and then log at OF_LOG_ERROR for another module.
Example of logging to a specific module:
// Set the default log level for all logging.
ofSetLogLevel(OF_LOG_ERROR);
// Selectively enable verbose logging for the MyClass module.
ofSetLogLevel("MyClass", OF_LOG_VERBOSE);
// If we then log the following ...
// Log a vermose message to a module called "MyClass".
ofLogVerbose("MyClass") << "A verbose message from MyClass.";
// Log a verbose message to a module called "MyOtherClass".
ofLogVerbose("MyOtherClass") << "A verbose message from MyOtherClass.";
// In this case, we will see the verbose message from "MyClass", but not
// the message from "MyOtherClass".