Changed log levels from numbers to text.

This commit is contained in:
Leon Styhre 2020-07-26 23:30:45 +02:00
parent 329a8da441
commit b5485b4ca9
21 changed files with 73 additions and 69 deletions

View file

@ -286,10 +286,10 @@ Starting EmulationStation with the --debug flag will provide feedback on whether
Example debug output:
```
Jul 12 11:28:58 lvl3: Sound::getFromTheme(): Looking for navigation sound tag <sound name="quicksysselect">.
Jul 12 11:28:58 lvl3: Sound::getFromTheme(): Tag found, ready to load theme sound file.
Jul 12 11:28:58 lvl3: Sound::getFromTheme(): Looking for navigation sound tag <sound name="select">.
Jul 12 11:28:58 lvl3: Sound::getFromTheme(): Tag not found, using fallback sound file.
Jul 12 11:28:58 Debug: Sound::getFromTheme(): Looking for navigation sound tag <sound name="quicksysselect">.
Jul 12 11:28:58 Debug: Sound::getFromTheme(): Tag found, ready to load theme sound file.
Jul 12 11:28:58 Debug: Sound::getFromTheme(): Looking for navigation sound tag <sound name="select">.
Jul 12 11:28:58 Debug: Sound::getFromTheme(): Tag not found, using fallback sound file.
```

View file

@ -148,7 +148,7 @@ void CollectionSystemManager::saveCustomCollection(SystemData* sys)
}
}
else {
LOG(LogError) << "Error - Couldn't find collection to save! " << name;
LOG(LogError) << "Couldn't find collection to save! " << name;
}
}

View file

@ -379,7 +379,7 @@ void FileData::sort(ComparisonFunction& comparator, bool ascending)
std::vector<FileData*> mChildrenShown;
for (unsigned int i = 0; i < mChildren.size(); i++) {
if (mChildren[i]->getHidden()) {
LOG(LogDebug) << "Debug - FileData::sort(): Skipping hidden game '" <<
LOG(LogDebug) << "FileData::sort(): Skipping hidden game '" <<
mChildren[i]->getName() << "'";
continue;
}
@ -420,7 +420,7 @@ void FileData::sortFavoritesOnTop(ComparisonFunction& comparator, bool ascending
for (unsigned int i = 0; i < mChildren.size(); i++) {
// Exclude game if it's marked as hidden and the hide setting has been set.
if (!showHiddenGames && mChildren[i]->getHidden()) {
LOG(LogDebug) << "Debug - FileData::sortFavoritesOnTop(): Skipping hidden game '" <<
LOG(LogDebug) << "FileData::sortFavoritesOnTop(): Skipping hidden game '" <<
mChildren[i]->getName() << "'";
continue;
}

View file

@ -128,7 +128,7 @@ void parseGamelist(SystemData* system)
relativeTo, false);
if (!trustGamelist && !Utils::FileSystem::exists(path)) {
LOG(LogWarning) << "Warning - File \"" << path << "\" does not exist, ignoring.";
LOG(LogWarning) << "File \"" << path << "\" does not exist, ignoring.";
continue;
}

View file

@ -101,8 +101,8 @@ bool SystemData::populateFolder(FileData* folder)
return false;
}
if (!Utils::FileSystem::isDirectory(folderPath)) {
LOG(LogWarning) << "Warning - Folder with path \"" <<
folderPath << "\" is not a directory!";
LOG(LogWarning) << "Folder with path \"" <<
folderPath << "\" is not a directory.";
return false;
}
@ -111,7 +111,7 @@ bool SystemData::populateFolder(FileData* folder)
// If this symlink resolves to somewhere that's at the beginning of our
// path, it's going to create a recursive loop. Make sure to avoid this.
if (folderPath.find(Utils::FileSystem::getCanonicalPath(folderPath)) == 0) {
LOG(LogWarning) << "Warning - Skipping infinitely recursive symlink \"" <<
LOG(LogWarning) << "Skipping infinitely recursive symlink \"" <<
folderPath << "\"";
return false;
}
@ -219,7 +219,7 @@ bool SystemData::loadConfig()
LOG(LogInfo) << "Loading system config file " << path << "...";
if (!Utils::FileSystem::exists(path)) {
LOG(LogWarning) << "Warning - es_systems.cfg does not exist.";
LOG(LogWarning) << "es_systems.cfg does not exist.";
if (copyConfigTemplate(getConfigPath(true)))
return false;
path = getConfigPath(false);
@ -233,7 +233,7 @@ bool SystemData::loadConfig()
#endif
if (!res) {
LOG(LogError) << "Error - Could not parse es_systems.cfg";
LOG(LogError) << "Could not parse es_systems.cfg";
LOG(LogError) << res.description();
return false;
}
@ -242,7 +242,7 @@ bool SystemData::loadConfig()
pugi::xml_node systemList = doc.child("systemList");
if (!systemList) {
LOG(LogError) << "Error - es_systems.cfg is missing the <systemList> tag!";
LOG(LogError) << "es_systems.cfg is missing the <systemList> tag.";
return false;
}
@ -288,7 +288,7 @@ bool SystemData::loadConfig()
// If there appears to be an actual platform ID supplied
// but it didn't match the list, generate a warning.
if (str != nullptr && str[0] != '\0' && platformId == PlatformIds::PLATFORM_UNKNOWN)
LOG(LogWarning) << "Warning - Unknown platform for system \"" << name <<
LOG(LogWarning) << "Unknown platform for system \"" << name <<
"\" (platform \"" << str << "\" from list \"" << platformList << "\")";
else if (platformId != PlatformIds::PLATFORM_UNKNOWN)
platformIds.push_back(platformId);
@ -299,8 +299,8 @@ bool SystemData::loadConfig()
// Validate.
if (name.empty() || path.empty() || extensions.empty() || cmd.empty()) {
LOG(LogError) << "Error - System \"" << name <<
"\" is missing name, path, extension, or command!";
LOG(LogError) << "System \"" << name <<
"\" is missing name, path, extension, or command.";
continue;
}
@ -363,7 +363,7 @@ bool SystemData::copyConfigTemplate(const std::string& path)
#endif
if (Utils::FileSystem::copyFile(systemsTemplateFile, path, false)) {
LOG(LogError) << "Error - Copying of es_systems.cfg template file failed.";
LOG(LogError) << "Copying of es_systems.cfg template file failed.";
return true;
}

View file

@ -347,7 +347,7 @@ bool verifyHomeFolderExists()
bool loadSystemConfigFile(std::string& errorMsg)
{
if (!SystemData::loadConfig()) {
LOG(LogError) << "Error - Could not parse systems configuration file.";
LOG(LogError) << "Could not parse systems configuration file.";
errorMsg = "COULDN'T FIND THE SYSTEMS CONFIGURATION FILE.\n"
"ATTEMPTED TO COPY A TEMPLATE ES_SYSTEMS.CFG FILE\n"
"FROM THE EMULATIONSTATION RESOURCES DIRECTORY,\n"
@ -358,7 +358,7 @@ bool loadSystemConfigFile(std::string& errorMsg)
}
if (SystemData::sSystemVector.size() == 0) {
LOG(LogError) << "Error - No systems found, does at least one system have a game present? "
LOG(LogError) << "No systems found, does at least one system have a game present? "
"(Check that the file extensions are supported.)";
errorMsg = "THE SYSTEMS CONFIGURATION FILE EXISTS, BUT NO\n"
"GAME FILES WERE FOUND. PLEASE MAKE SURE THAT\n"
@ -534,7 +534,7 @@ int main(int argc, char* argv[])
// Check if the media directory exists, and if not, log a warning.
if (!Utils::FileSystem::isDirectory(FileData::getMediaDirectory()) ||
Utils::FileSystem::isSymlink(FileData::getMediaDirectory())) {
LOG(LogWarning) << "Warning - Games media directory does not exist "
LOG(LogWarning) << "Games media directory does not exist "
"(or is not a directory or a symlink):";
LOG(LogWarning) << FileData::getMediaDirectory();
}

View file

@ -161,7 +161,7 @@ void thegamesdb_generate_json_scraper_requests(
first = false;
}
else {
LOG(LogWarning) << "Warning - TheGamesDB scraper warning - "
LOG(LogWarning) << "TheGamesDB scraper warning - "
"no support for platform " << getPlatformName(*platformIt);
}
}
@ -380,7 +380,7 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr<HttpReq>& req,
if (doc.HasParseError()) {
std::string err =
std::string("Error - TheGamesDBJSONRequest - Error parsing JSON. \n\t") +
std::string("TheGamesDBJSONRequest - Error parsing JSON. \n\t") +
GetParseError_En(doc.GetParseError());
setError(err);
LOG(LogError) << err;
@ -399,8 +399,7 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr<HttpReq>& req,
baseImageUrlLarge = base_url["large"].GetString();
}
else {
std::string warn = "Warning - TheGamesDBJSONRequest - No URL path for large images.\n";
LOG(LogWarning) << warn;
LOG(LogWarning) << "TheGamesDBJSONRequest - No URL path for large images.\n";
return;
}
@ -408,7 +407,7 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr<HttpReq>& req,
processMediaURLs(images, baseImageUrlLarge, results);
}
catch (std::runtime_error& e) {
LOG(LogError) << "Error - Error while processing media URLs: " << e.what();
LOG(LogError) << "Error while processing media URLs: " << e.what();
}
// Find how many more requests we can make before the scraper
@ -427,8 +426,7 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr<HttpReq>& req,
// These process steps are for the initial scraping response.
if (!doc.HasMember("data") || !doc["data"].HasMember("games") ||
!doc["data"]["games"].IsArray()) {
std::string warn = "Warning - TheGamesDBJSONRequest - Response had no game data.\n";
LOG(LogWarning) << warn;
LOG(LogWarning) << "TheGamesDBJSONRequest - Response had no game data.\n";
return;
}
@ -441,7 +439,7 @@ void TheGamesDBJSONRequest::process(const std::unique_ptr<HttpReq>& req,
processGame(v, results);
}
catch (std::runtime_error& e) {
LOG(LogError) << "Error - Error while processing game: " << e.what();
LOG(LogError) << "Error while processing game: " << e.what();
}
}
}

View file

@ -125,14 +125,14 @@ bool TheGamesDBJSONRequestResources::saveResource(
{
if (req == nullptr) {
LOG(LogError) << "Error - HTTP request pointer was null.\n";
LOG(LogError) << "HTTP request pointer was null.\n";
return true;
}
if (req->status() == HttpReq::REQ_IN_PROGRESS) {
return false; // Not ready: wait some more.
}
if (req->status() != HttpReq::REQ_SUCCESS) {
LOG(LogError) << "Error - Resource request for " << file_name <<
LOG(LogError) << "Resource request for " << file_name <<
" failed:\n\t" << req->getErrorMsg();
return true; // Request failed, resetting request..
}

View file

@ -31,8 +31,7 @@ std::unique_ptr<ScraperSearchHandle> startScraperSearch(const ScraperSearchParam
// Check if the scraper in the settings still exists as a registered scraping source.
if (scraper_request_funcs.find(name) == scraper_request_funcs.end())
LOG(LogWarning) << "Warning - Configured scraper (" << name <<
") unavailable, scraping aborted.";
LOG(LogWarning) << "Configured scraper (" << name << ") unavailable, scraping aborted.";
else
scraper_request_funcs.at(name)(params, handle->mRequestQueue, handle->mResults);
@ -47,8 +46,7 @@ std::unique_ptr<ScraperSearchHandle> startMediaURLsFetch(const std::string& game
ScraperSearchParams params;
// Check if the scraper in the settings still exists as a registered scraping source.
if (scraper_request_funcs.find(name) == scraper_request_funcs.end()) {
LOG(LogWarning) << "Warning - Configured scraper (" << name <<
") unavailable, scraping aborted.";
LOG(LogWarning) << "Configured scraper (" << name << ") unavailable, scraping aborted.";
}
else {
// Specifically use the TheGamesDB function as this type of request
@ -145,7 +143,7 @@ void ScraperHttpRequest::update()
return;
// Everything else is some sort of error.
LOG(LogError) << "Error - ScraperHttpRequest network error (status: " << status<< ") - "
LOG(LogError) << "ScraperHttpRequest network error (status: " << status<< ") - "
<< mReq->getErrorMsg();
setError(mReq->getErrorMsg());
}
@ -407,7 +405,7 @@ bool resizeImage(const std::string& path, int maxWidth, int maxHeight)
if (format == FIF_UNKNOWN)
format = FreeImage_GetFIFFromFilename(path.c_str());
if (format == FIF_UNKNOWN) {
LOG(LogError) << "Error - Could not detect filetype for image \"" << path << "\"!";
LOG(LogError) << "Could not detect filetype for image \"" << path << "\"!";
return false;
}
@ -416,7 +414,7 @@ bool resizeImage(const std::string& path, int maxWidth, int maxHeight)
image = FreeImage_Load(format, path.c_str());
}
else {
LOG(LogError) << "Error - File format not supported for image \"" << path << "\"!";
LOG(LogError) << "File format not supported for image \"" << path << "\"!";
return false;
}
@ -437,7 +435,7 @@ bool resizeImage(const std::string& path, int maxWidth, int maxHeight)
FreeImage_Unload(image);
if (imageRescaled == nullptr) {
LOG(LogError) << "Error - Could not resize image! (not enough memory? invalid bitdepth?)";
LOG(LogError) << "Could not resize image. (Not enough memory? Invalid bitdepth?)";
return false;
}
@ -445,7 +443,7 @@ bool resizeImage(const std::string& path, int maxWidth, int maxHeight)
FreeImage_Unload(imageRescaled);
if (!saved) {
LOG(LogError) << "Error - Failed to save resized image!";
LOG(LogError) << "Failed to save resized image.";
}
return saved;

View file

@ -149,7 +149,7 @@ void screenscraper_generate_scraper_requests(const ScraperSearchParams& params,
p_ids.push_back(mapIt->second);
}
else {
LOG(LogWarning) << "Warning - ScreenScraper: no support for platform " <<
LOG(LogWarning) << "ScreenScraper: no support for platform " <<
getPlatformName(*platformIt);
// Add the scrape request without a platform/system ID.
requests.push(std::unique_ptr<ScraperRequest>
@ -180,7 +180,7 @@ void ScreenScraperRequest::process(const std::unique_ptr<HttpReq>& req,
if (!parseResult) {
std::stringstream ss;
ss << "Error - ScreenScraperRequest - Error parsing XML: " << parseResult.description();
ss << "ScreenScraperRequest - Error parsing XML: " << parseResult.description();
std::string err = ss.str();
setError(err);

View file

@ -102,7 +102,7 @@ void AudioManager::init()
// Open the audio device and pause.
if (SDL_OpenAudio(&sAudioFormat, nullptr) < 0) {
LOG(LogError) << "AudioManager Error - Unable to open SDL audio: " <<
LOG(LogError) << "AudioManager - Unable to open SDL audio: " <<
SDL_GetError() << std::endl;
}
}
@ -134,7 +134,7 @@ void AudioManager::unregisterSound(std::shared_ptr<Sound> & sound)
return;
}
}
LOG(LogError) << "AudioManager Error - tried to unregister a sound that wasn't registered!";
LOG(LogError) << "AudioManager - tried to unregister a sound that wasn't registered!";
}
void AudioManager::play()

View file

@ -61,11 +61,11 @@ std::vector<unsigned char> ImageIO::loadFromMemoryRGBA32(const unsigned char * d
}
}
else {
LOG(LogError) << "Error - Failed to load image from memory!";
LOG(LogError) << "Failed to load image from memory!";
}
}
else {
LOG(LogError) << "Error - Couldn't load image, file is missing or the file type is " <<
LOG(LogError) << "Couldn't load image, file is missing or the file type is " <<
// it's not existing or the file type " <<
(format == FIF_UNKNOWN ? "unknown" : "unsupported") << "!";
}

View file

@ -196,7 +196,7 @@ void InputConfig::loadFromXML(pugi::xml_node& node)
InputType typeEnum = stringToInputType(type);
if (typeEnum == TYPE_COUNT) {
LOG(LogError) << "Error - InputConfig load error - input of type \"" << type <<
LOG(LogError) << "InputConfig load error - input of type \"" << type <<
"\" is invalid! Skipping input \"" << name << "\".\n";
continue;
}
@ -205,7 +205,7 @@ void InputConfig::loadFromXML(pugi::xml_node& node)
int value = input.attribute("value").as_int();
if (value == 0) {
LOG(LogWarning) << "Warning - InputConfig value is 0 for " <<
LOG(LogWarning) << "InputConfig value is 0 for " <<
type << " " << id << "!\n";
}

View file

@ -142,7 +142,7 @@ void InputManager::removeJoystickByJoystickID(SDL_JoystickID joyId)
mJoysticks.erase(joyIt);
}
else {
LOG(LogError) << "Error - Could not find joystick to close (instance ID: " << joyId << ")";
LOG(LogError) << "Could not find joystick to close (instance ID: " << joyId << ")";
}
}
@ -472,7 +472,7 @@ void InputManager::doOnFinish()
#endif
if (!result) {
LOG(LogError) << "Error - Couldn't parse input config: " << result.description();
LOG(LogError) << "Couldn't parse input config: " << result.description();
}
else {
pugi::xml_node root = doc.child("inputList");
@ -546,7 +546,7 @@ std::string InputManager::getDeviceGUIDString(int deviceId)
auto it = mJoysticks.find(deviceId);
if (it == mJoysticks.cend()) {
LOG(LogError) << "Error - getDeviceGUIDString - deviceId " << deviceId << " not found!";
LOG(LogError) << "getDeviceGUIDString - deviceId " << deviceId << " not found!";
return "something went horribly wrong";
}

View file

@ -52,7 +52,7 @@ void Log::open()
std::ostringstream& Log::get(LogLevel level)
{
time_t t = time(nullptr);
os << std::put_time(localtime(&t), "%b %d %T ") << "lvl" << level << ": \t";
os << std::put_time(localtime(&t), "%b %d %T ") << logLevelMap[level] << ":\t";
messageLevel = level;
return os;

View file

@ -9,6 +9,7 @@
#define ES_CORE_LOG_H
#include <sstream>
#include <map>
#define LOG(level) \
if (level > Log::getReportingLevel()); \
@ -41,6 +42,13 @@ protected:
std::ostringstream os;
private:
std::map<LogLevel, std::string> logLevelMap {
{ LogError, "Error" },
{ LogWarning, "Warn" },
{ LogInfo, "Info" },
{ LogDebug, "Debug" }
};
static LogLevel reportingLevel;
LogLevel messageLevel;
};

View file

@ -78,7 +78,7 @@ int launchEmulatorUnix(const std::string& cmd_utf8)
int returnValue;
if (!(commandPipe = (FILE*)popen(command.c_str(), "r"))) {
LOG(LogError) << "Error - couldn't open pipe to command.";
LOG(LogError) << "Couldn't open pipe to command.";
return -1;
}
@ -97,7 +97,7 @@ int launchEmulatorUnix(const std::string& cmd_utf8)
}
if (returnValue) {
LOG(LogError) << "Error - launchEmulatorUnix - return value " <<
LOG(LogError) << "launchEmulatorUnix - return value " <<
std::to_string(returnValue) + ":";
if (commandOutput.size())
LOG(LogError) << commandOutput;
@ -170,7 +170,7 @@ int launchEmulatorWindows(const std::wstring& cmd_utf16)
}
}
LOG(LogError) << "Error - launchEmulatorWindows - system error code " <<
LOG(LogError) << "launchEmulatorWindows - system error code " <<
errorCode << ": " << errorMessage;
}
@ -230,7 +230,7 @@ int quitES(QuitMode mode)
void emergencyShutdown()
{
LOG(LogError) << "Critical Error - Performing emergency shutdown...";
LOG(LogError) << "Critical - Performing emergency shutdown...";
MameNames::deinit();
AudioManager::getInstance()->deinit();

View file

@ -306,7 +306,7 @@ void Settings::loadFile()
pugi::xml_parse_result result = doc.load_file(path.c_str());
#endif
if (!result) {
LOG(LogError) << "Error - Could not parse Settings file!\n " << result.description();
LOG(LogError) << "Could not parse Settings file.\n " << result.description();
return;
}
@ -326,7 +326,7 @@ void Settings::loadFile()
type Settings::getMethodName(const std::string& name) \
{ \
if (mapName.find(name) == mapName.cend()) { \
LOG(LogError) << "Error - Tried to use unset setting " << name << "!"; \
LOG(LogError) << "Tried to use unset setting " << name << "!"; \
} \
return mapName[name]; \
} \

View file

@ -117,7 +117,7 @@ void Sound::init()
Uint8 * data = nullptr;
Uint32 dlen = 0;
if (SDL_LoadWAV(mPath.c_str(), &wave, &data, &dlen) == nullptr) {
LOG(LogError) << "Error - Failed to load theme navigation sound file:";
LOG(LogError) << "Failed to load theme navigation sound file:";
LOG(LogError) << SDL_GetError();
return;
}

View file

@ -67,7 +67,7 @@ std::string ResourceManager::getResourcePath(const std::string& path) const
// For missing resources, log an error and terminate the application. This should
// indicate that we have a broken EmulationStation installation.
else {
LOG(LogError) << "Error - Program resource missing: " << path;
LOG(LogError) << "Program resource missing: " << path;
LOG(LogError) << "Tried to find the resource in the following locations:";
LOG(LogError) << testHome;
#ifdef __unix__

View file

@ -544,19 +544,19 @@ namespace Utils
const std::string& _destination_path, bool _overwrite)
{
if (!exists(_source_path)) {
LOG(LogError) << "Error - Can't copy file, source file does not exist:";
LOG(LogError) << "Can't copy file, source file does not exist:";
LOG(LogError) << _source_path;
return true;
}
if (isDirectory(_destination_path)) {
LOG(LogError) << "Error - Destination file is actually a directory:";
LOG(LogError) << "Destination file is actually a directory:";
LOG(LogError) << _destination_path;
return true;
}
if (!_overwrite && exists(_destination_path)) {
LOG(LogError) << "Error - Destination file exists and the overwrite flag "
LOG(LogError) << "Destination file exists and the overwrite flag "
"has not been set.";
return true;
}
@ -569,7 +569,7 @@ namespace Utils
#endif
if (sourceFile.fail()) {
LOG(LogError) << "Error - Couldn't read from source file (" << _source_path <<
LOG(LogError) << "Couldn't read from source file (" << _source_path <<
"), permission problems?";
sourceFile.close();
return true;
@ -583,7 +583,7 @@ namespace Utils
#endif
if (targetFile.fail()) {
LOG(LogError) << "Error - Couldn't write to target file (" << _destination_path <<
LOG(LogError) << "Couldn't write to target file (" << _destination_path <<
"), permission problems?";
targetFile.close();
return true;
@ -608,13 +608,13 @@ namespace Utils
}
if (isDirectory(_destination_path)) {
LOG(LogError) << "Error - Destination file is actually a directory:";
LOG(LogError) << "Destination file is actually a directory:";
LOG(LogError) << _destination_path;
return true;
}
if (!_overwrite && exists(_destination_path)) {
LOG(LogError) << "Error - Destination file exists and the overwrite flag "
LOG(LogError) << "Destination file exists and the overwrite flag "
"has not been set.";
return true;
}
@ -640,7 +640,7 @@ namespace Utils
// Try to remove file.
#ifdef _WIN64
if (_wunlink(Utils::String::stringToWideString(path).c_str()) != 0) {
LOG(LogError) << "Error - Couldn't delete file, permission problems?";
LOG(LogError) << "Couldn't delete file, permission problems?";
LOG(LogError) << path;
return true;
}
@ -649,7 +649,7 @@ namespace Utils
}
#else
if (unlink(path.c_str()) != 0) {
LOG(LogError) << "Error - Couldn't delete file, permission problems?";
LOG(LogError) << "Couldn't delete file, permission problems?";
LOG(LogError) << path;
return true;
}