Streamline logging a little

master
outfrost 2020-05-02 21:30:35 +02:00
parent fd220501c6
commit 731332db53
3 changed files with 14 additions and 16 deletions

View File

@ -16,6 +16,7 @@ static const char* replaceFileExtension(const AiString path, const char* ext);
const Solid* importSolid(const char* path) {
const AiScene* scene = importScene(path);
if (scene == NULL) {
logError("Failed to import solid from %s", path);
return NULL;
}
@ -102,7 +103,7 @@ const Solid* importSolid(const char* path) {
TgaImage* textureImage = readTga(texturePath);
if (textureImage == NULL) {
logError("Asset texture file not found: %s", texturePath);
logError("Importing solid from %s: Cannot read texture file %s", path, texturePath);
}
else {
glTexImage2D(GL_TEXTURE_2D,
@ -129,10 +130,7 @@ const Solid* importSolid(const char* path) {
static const AiScene* importScene(const char* path) {
const AiScene* scene = aiImportFile(path, aiProcess_PreTransformVertices);
if (scene == NULL) {
logError("Failed to import asset from %s", path);
}
else if (scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE) {
if (scene != NULL && scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE) {
logError("Incomplete scene imported from %s", path);
aiReleaseImport(scene);
scene = NULL;

View File

@ -7,7 +7,7 @@ LogLevel logLevel = LOGLEVEL_DEBUG;
void logMessage(LogLevel msgLevel, const char* file, int line, const char* message, ...) {
void logMessage(LogLevel msgLevel, const char* func, const char* message, ...) {
if (msgLevel > logLevel) {
return;
}
@ -15,26 +15,26 @@ void logMessage(LogLevel msgLevel, const char* file, int line, const char* messa
const char* msgLevelString;
switch (msgLevel) {
case LOGLEVEL_ERROR:
msgLevelString = "error: ";
msgLevelString = "ERROR ";
break;
case LOGLEVEL_WARNING:
msgLevelString = "warning: ";
msgLevelString = "WARNING ";
break;
case LOGLEVEL_INFO:
msgLevelString = "";
break;
case LOGLEVEL_DEBUG:
msgLevelString = "debug: ";
msgLevelString = "DEBUG ";
break;
default:
msgLevelString = "(invalid message level!) ";
msgLevelString = "(invalid message level) ";
break;
}
va_list args;
va_start(args, message);
fprintf(stderr, "%s:%i: %s", file, line, msgLevelString);
fprintf(stderr, "%s %s:: ", func, msgLevelString);
vfprintf(stderr, message, args);
fputc('\n', stderr);

View File

@ -10,11 +10,11 @@ typedef enum {
LogLevel logLevel;
#define logError(...) logMessage(LOGLEVEL_ERROR, __FILE__, __LINE__, __VA_ARGS__)
#define logWarning(...) logMessage(LOGLEVEL_WARNING, __FILE__, __LINE__, __VA_ARGS__)
#define logInfo(...) logMessage(LOGLEVEL_INFO, __FILE__, __LINE__, __VA_ARGS__)
#define logDebug(...) logMessage(LOGLEVEL_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
#define logError(...) logMessage(LOGLEVEL_ERROR, __func__, __VA_ARGS__)
#define logWarning(...) logMessage(LOGLEVEL_WARNING, __func__, __VA_ARGS__)
#define logInfo(...) logMessage(LOGLEVEL_INFO, __func__, __VA_ARGS__)
#define logDebug(...) logMessage(LOGLEVEL_DEBUG, __func__, __VA_ARGS__)
void logMessage(LogLevel msgLevel, const char* file, int line, const char* message, ...);
void logMessage(LogLevel msgLevel, const char* func, const char* message, ...);
#endif