mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Replace logging API
Allow clients to provide a callback function that the LOOT API will use when logging. This provides more flexibility than the previous choice of outputting to an exclusive file or the console.
This commit is contained in:
+9
-15
@@ -25,6 +25,7 @@
|
||||
#ifndef LOOT_API_H
|
||||
#define LOOT_API_H
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
@@ -36,7 +37,7 @@
|
||||
#include "loot/exception/file_access_error.h"
|
||||
#include "loot/exception/git_state_error.h"
|
||||
#include "loot/enum/game_type.h"
|
||||
#include "loot/enum/log_verbosity.h"
|
||||
#include "loot/enum/log_level.h"
|
||||
#include "loot/loot_version.h"
|
||||
|
||||
namespace loot {
|
||||
@@ -47,21 +48,14 @@ namespace loot {
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* @brief Set the API's logging verbosity.
|
||||
* @details The default is ``LogVerbosity::off``.
|
||||
* @param verbosity
|
||||
* The logging verbosity to set.
|
||||
* @brief Set the callback function that is called when logging.
|
||||
* @details If this function is not called, the default behaviour is to
|
||||
* print messages to the console.
|
||||
* @param callback
|
||||
* The function called when logging. The first parameter is the
|
||||
* level of the message being logged, and the second is the message.
|
||||
*/
|
||||
LOOT_API void SetLoggingVerbosity(LogVerbosity verbosity);
|
||||
|
||||
/**
|
||||
* @brief Set the file path that logging statements are written to.
|
||||
* @details If no file is set the default behaviour is to print logging
|
||||
* statements to the console.
|
||||
* @param path
|
||||
* The log file path.
|
||||
*/
|
||||
LOOT_API void SetLogFile(const std::string& path);
|
||||
LOOT_API void SetLoggingCallback(std::function<void(LogLevel, const char*)> callback);
|
||||
|
||||
/**@}*/
|
||||
/**********************************************************************//**
|
||||
|
||||
@@ -22,20 +22,23 @@ along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOOT_LOG_VERBOSITY
|
||||
#define LOOT_LOG_VERBOSITY
|
||||
#ifndef LOOT_LOG_LEVEL
|
||||
#define LOOT_LOG_LEVEL
|
||||
|
||||
/**
|
||||
* The namespace used by the LOOT API.
|
||||
*/
|
||||
namespace loot {
|
||||
/**
|
||||
* @brief Codes used to specify different levels of API logging verbosity.
|
||||
* @brief Codes used to specify different levels of API logging.
|
||||
*/
|
||||
enum struct LogVerbosity : unsigned int {
|
||||
off,
|
||||
warning,
|
||||
enum struct LogLevel : unsigned int {
|
||||
trace,
|
||||
debug,
|
||||
info,
|
||||
warning,
|
||||
error,
|
||||
fatal
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user