Skip to content

Commit

Permalink
Reduce logging of invalid files
Browse files Browse the repository at this point in the history
Comment the logging of invalid files to reduce the log spam. Add logging of the number of ignored files in the playlist generation.
  • Loading branch information
laszloh committed Feb 13, 2024
1 parent abb4f8c commit dea89a2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/SdCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,21 @@ bool fileValid(const char *_fileItem) {
}
if (*(lastSlashPtr + 1) == '.') {
// we have a hidden file
Log_Printf(LOGLEVEL_DEBUG, "File is hidden: %s", _fileItem);
// Log_Printf(LOGLEVEL_DEBUG, "File is hidden: %s", _fileItem);
return false;
}

// extract the file extension
const char *extStartPtr = strrchr(_fileItem, '.');
if (extStartPtr == nullptr) {
// no extension found
Log_Printf(LOGLEVEL_DEBUG, "File has no extension: %s", _fileItem);
// Log_Printf(LOGLEVEL_DEBUG, "File has no extension: %s", _fileItem);
return false;
}
const size_t extLen = strlen(extStartPtr);
if (extLen > maxExtLen) {
// extension too long, we do not care anymore
Log_Printf(LOGLEVEL_DEBUG, "File not supported (extension to long): %s", _fileItem);
// Log_Printf(LOGLEVEL_DEBUG, "File not supported (extension to long): %s", _fileItem);
return false;
}
char extBuffer[maxExtLen + 1] = {0};
Expand All @@ -197,8 +197,8 @@ bool fileValid(const char *_fileItem) {
return true;
}
}
// miss, we did not found nothing
Log_Printf(LOGLEVEL_DEBUG, "File not supported: %s", _fileItem);
// miss, we did not find the extension
// Log_Printf(LOGLEVEL_DEBUG, "File not supported: %s", _fileItem);
return false;
}

Expand Down Expand Up @@ -340,6 +340,7 @@ std::optional<Playlist *> SdCard_ReturnPlaylist(const char *fileName, const uint

// Directory-mode (linear-playlist)
playlist->reserve(64); // reserve a sane amount of memory to reduce the number of reallocs
size_t hiddenFiles = 0;
while (true) {
bool isDir;
const String name = fileOrDirectory.getNextFileName(&isDir);
Expand All @@ -356,10 +357,13 @@ std::optional<Playlist *> SdCard_ReturnPlaylist(const char *fileName, const uint
// OOM, function already took care of house cleaning
return std::nullopt;
}
} else {
hiddenFiles++;
}
}
playlist->shrink_to_fit();

Log_Printf(LOGLEVEL_NOTICE, numberOfValidFiles, playlist->size());
Log_Printf(LOGLEVEL_DEBUG, "Hidden files: %u", hiddenFiles);
return playlist;
}

0 comments on commit dea89a2

Please sign in to comment.