Skip to content

Commit

Permalink
Fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Immanuel-C committed Feb 18, 2024
1 parent 8304016 commit 3e89d44
Showing 1 changed file with 43 additions and 49 deletions.
92 changes: 43 additions & 49 deletions ILog.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
extern "C" {
#endif
// Github repo link https://github.com/Immanuel-C/ILog
// This library is under the MIT licence
// Github repo link https://github.com/Immanuel-C/ILog
// This library is under the MIT licence

#include "ILogCore.h"
#include "DebugBreak.h"
Expand All @@ -19,7 +19,7 @@ extern "C" {


#ifdef _WIN32
#include <windows.h>
#include <windows.h>
#endif // _WIN32

#define _I_COLOUR_WHITE 1
Expand All @@ -30,115 +30,109 @@ extern "C" {

#define __I_DEBUG_BREAK() debug_break()

#if defined(_MSC_VER)
#define _I_VA_ARGS __VS_ARGS__
#else
#define _I_VA_ARGS ##__VS_ARGS__
#endif

#if !defined(NDEBUG)

#define I_DEBUG_LOG_TRACE(msg, ...) _i_log(stdout, "Debug Trace: ", msg, _I_COLOUR_GREEN, _I_VA_ARGS)
#define I_DEBUG_LOG_INFO(msg, ...) _i_log(stdout, "Debug Info: ", msg, _I_COLOUR_WHITE, _I_VA_ARGS)
#define I_DEBUG_LOG_WARNING(msg, ...) _i_log(stdout, "Debug Warning: ", msg, _I_COLOUR_YELLOW, _I_VA_ARGS)
#define I_DEBUG_LOG_ERROR(msg, ...) _i_log(stderr, "Debug Error: ", msg, _I_COLOUR_RED, _I_VA_ARGS)
#define I_DEBUG_LOG_FATAL_ERROR(msg, ...) _i_log(stderr, "Debug Fatal Error: ", msg, _I_COLOUR_FATAL_RED, _I_VA_ARGS)
#define I_DEBUG_LOG_TRACE(msg, ...) _i_log(stdout, "Debug Trace: ", msg, _I_COLOUR_GREEN, ##__VA_ARGS__)
#define I_DEBUG_LOG_INFO(msg, ...) _i_log(stdout, "Debug Info: ", msg, _I_COLOUR_WHITE, ##__VA_ARGS__)
#define I_DEBUG_LOG_WARNING(msg, ...) _i_log(stdout, "Debug Warning: ", msg, _I_COLOUR_YELLOW, ##__VA_ARGS__)
#define I_DEBUG_LOG_ERROR(msg, ...) _i_log(stderr, "Debug Error: ", msg, _I_COLOUR_RED, ##__VA_ARGS__)
#define I_DEBUG_LOG_FATAL_ERROR(msg, ...) _i_log(stderr, "Debug Fatal Error: ", msg, _I_COLOUR_FATAL_RED, ##__VA_ARGS__)

#define I_DEBUG_FILE_LOG(fileName, msg, mode, ...) _f_i_log(fileName, msg, mode, _I_VA_ARGS)
#define I_DEBUG_FS_LOG(stream, msg, ...) _i_log(stream, "", msg, 0, _I_VA_ARGS)
#define I_DEBUG_FILE_LOG(fileName, msg, mode, ...) _f_i_log(fileName, msg, mode, ##__VA_ARGS__)
#define I_DEBUG_FS_LOG(stream, msg, ...) _i_log(stream, "", msg, 0, ##__VA_ARGS__)

#define I_DEBUG_ASSERT_ERROR(condition, msg, ...) \
#define I_DEBUG_ASSERT_ERROR(condition, msg, ...) \
{ \
if(condition) \
{ \
const char* prefixMsg = "Debug Error: Assertion Failed On Line: %u\nIn File: %s\n"; \
char* buf = (char*)malloc(strlen(prefixMsg) * sizeof(char) + strlen(__FILE__) * sizeof(char) + sizeof(unsigned int)); \
sprintf(buf, prefixMsg, (unsigned int)(__LINE__), __FILE__); \
_i_log(stderr, buf, msg, _I_COLOUR_RED, _I_VA_ARGS); \
_i_log(stderr, buf, msg, _I_COLOUR_RED, ##__VA_ARGS__); \
free(buf); \
__I_DEBUG_BREAK(); \
} \
}


#define I_DEBUG_ASSERT_FATAL_ERROR(condition, msg, ...) \
#define I_DEBUG_ASSERT_FATAL_ERROR(condition, msg, ...) \
{ \
if(condition) \
{ \
const char* prefixMsg = "Debug Fatal Error: Assertion Failed On Line: %u\nIn File: %s\n"; \
char* buf = (char*)malloc(strlen(prefixMsg) * sizeof(char) + strlen(__FILE__) * sizeof(char) + sizeof(unsigned int)); \
sprintf(buf, prefixMsg, (unsigned int)(__LINE__), __FILE__); \
_i_log(stderr, buf, msg, _I_COLOUR_FATAL_RED, _I_VA_ARGS); \
_i_log(stderr, buf, msg, _I_COLOUR_FATAL_RED, ##__VA_ARGS__); \
free(buf); \
__I_DEBUG_BREAK(); \
} \
}


#else

#define I_DEBUG_LOG_TRACE(msg, ...)
#define I_DEBUG_LOG_INFO(msg, ...)
#define I_DEBUG_LOG_WARNING(msg, ...)
#define I_DEBUG_LOG_ERROR(msg, ...)
#define I_DEBUG_LOG_FATAL_ERROR(msg, ...)
#else

#define I_DEBUG_ASSERT_ERROR(condition, msg, ...)
#define I_DEBUG_LOG_TRACE(msg, ...)
#define I_DEBUG_LOG_INFO(msg, ...)
#define I_DEBUG_LOG_WARNING(msg, ...)
#define I_DEBUG_LOG_ERROR(msg, ...)
#define I_DEBUG_LOG_FATAL_ERROR(msg, ...)

#define I_DEBUG_ASSERT_FATAL_ERROR(condition, msg, ...)
#define I_DEBUG_ASSERT_ERROR(condition, msg, ...)

#define I_DEBUG_FILE_LOG(fileName, msg, ...)
#define I_DEBUG_FS_LOG(stream, msg, ...)
#define I_DEBUG_ASSERT_FATAL_ERROR(condition, msg, ...)

#define I_DEBUG_FILE_LOG(fileName, msg, ...)
#define I_DEBUG_FS_LOG(stream, msg, ...)

#endif

#define I_LOG_TRACE(msg, ...) _i_log(stdout, "Trace: ", msg, _I_COLOUR_GREEN, _I_VA_ARGS)
#define I_LOG_INFO(msg, ...) _i_log(stdout, "Info: ", msg, _I_COLOUR_WHITE, _I_VA_ARGS)
#define I_LOG_WARNING(msg, ...) _i_log(stdout, "Warning: ", msg, _I_COLOUR_YELLOW, _I_VA_ARGS)
#define I_LOG_ERROR(msg, ...) _i_log(stderr, "Error: ", msg, _I_COLOUR_RED, _I_VA_ARGS)
#define I_LOG_FATAL_ERROR(msg, ...) _i_log(stderr, "Fatal Error: ", msg, _I_COLOUR_FATAL_RED, _I_VA_ARGS)
#endif

#define I_LOG_TRACE(msg, ...) _i_log(stdout, "Trace: ", msg, _I_COLOUR_GREEN, ##__VA_ARGS__)
#define I_LOG_INFO(msg, ...) _i_log(stdout, "Info: ", msg, _I_COLOUR_WHITE, ##__VA_ARGS__)
#define I_LOG_WARNING(msg, ...) _i_log(stdout, "Warning: ", msg, _I_COLOUR_YELLOW, ##__VA_ARGS__)
#define I_LOG_ERROR(msg, ...) _i_log(stderr, "Error: ", msg, _I_COLOUR_RED, ##__VA_ARGS__)
#define I_LOG_FATAL_ERROR(msg, ...) _i_log(stderr, "Fatal Error: ", msg, _I_COLOUR_FATAL_RED, ##__VA_ARGS__)

#define I_FILE_LOG(fileName, msg, mode, ...) _f_i_log(fileName, msg, mode, _I_VA_ARGS)
#define I_FS_LOG(stream, msg, ...) _i_log(stream, "", msg, 0, _I_VA_ARGS)
#define I_FILE_LOG(fileName, msg, mode, ...) _f_i_log(fileName, msg, mode, ##__VA_ARGS__)
#define I_FS_LOG(stream, msg, ...) _i_log(stream, "", msg, 0, ##__VA_ARGS__)


#define I_ASSERT_ERROR(condition, msg, ...) \
#define I_ASSERT_ERROR(condition, msg, ...) \
{ \
if(condition) \
{ \
const char* prefixMsg = "Error: Assertion Failed On Line: %u\nIn File: %s\n"; \
char* buf = (char*)malloc(strlen(prefixMsg) * sizeof(char) + strlen(__FILE__) * sizeof(char) + sizeof(unsigned int)); \
sprintf(buf, prefixMsg, (unsigned int)(__LINE__), __FILE__); \
_i_log(stderr, buf, msg, _I_COLOUR_RED, _I_VA_ARGS); \
_i_log(stderr, buf, msg, _I_COLOUR_RED, ##__VA_ARGS__); \
free(buf); \
__I_DEBUG_BREAK(); \
} \
}


#define I_ASSERT_FATAL_ERROR(condition, msg, ...) \
#define I_ASSERT_FATAL_ERROR(condition, msg, ...) \
{ \
if(condition) \
{ \
const char* prefixMsg = "Fatal Error: Assertion Failed On Line: %u\nIn File: %s\n"; \
char* buf = (char*)malloc(strlen(prefixMsg) * sizeof(char) + strlen(__FILE__) * sizeof(char) + sizeof(unsigned int)); \
sprintf(buf, prefixMsg, (unsigned int)(__LINE__), __FILE__); \
_i_log(stderr, buf, msg, _I_COLOUR_FATAL_RED, _I_VA_ARGS); \
_i_log(stderr, buf, msg, _I_COLOUR_FATAL_RED, ##__VA_ARGS__); \
free(buf); \
__I_DEBUG_BREAK(); \
} \
}


// DO NOT USE
ILOG_API void _platformLog(FILE* stream, const char* msg, int colour);
// DO NOT USE
ILOG_API void _i_log(FILE* stream, const char* prefix, const char* msg, int colour, ...);
// DO NOT USE
ILOG_API void _f_i_log(const char* fileName, const char* msg, const char* mode, ...);
ILOG_API void _platformLog(FILE* stream, const char* msg, int colour);
// DO NOT USE
ILOG_API void _i_log(FILE* stream, const char* prefix, const char* msg, int colour, ...);
// DO NOT USE
ILOG_API void _f_i_log(const char* fileName, const char* msg, const char* mode, ...);

#if defined(__cplusplus)
#if defined(__cplusplus)
}
#endif

Expand Down

0 comments on commit 3e89d44

Please sign in to comment.