-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e86128b
commit 999c017
Showing
18 changed files
with
203 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,154 +1,24 @@ | ||
/* | ||
I Took this from a github... but I can't find it right now for giving the credits :( | ||
*/ | ||
#define LOG_LEVEL INFO | ||
|
||
#ifndef OMSimLogger_h | ||
#define OMSimLogger_h 1 | ||
|
||
#include <stdio.h> | ||
#include <time.h> | ||
|
||
/* Default level */ | ||
#ifndef LOG_LEVEL | ||
#define LOG_LEVEL WARNING | ||
#endif | ||
|
||
/* Colour customization */ | ||
#define DEBUG_COLOUR "" | ||
#define INFO_COLOUR "\x1B[36m" | ||
#define NOTICE_COLOUR "\x1B[32;1m" | ||
#define WARNING_COLOUR "\x1B[33m" | ||
#define ERROR_COLOUR "\x1B[31m" | ||
#define CRITICAL_COLOUR "\x1B[41;1m" | ||
|
||
/* Do not change this. */ | ||
#define RESET_COLOUR "\x1B[0m" | ||
|
||
/* Formatting prefs. */ | ||
#define MSG_ENDING "\n" | ||
#define TIME_FORMAT "%T" | ||
#define BORDER "-" | ||
|
||
/* Enabler flags */ | ||
#define DISPLAY_COLOUR 1 | ||
#define DISPLAY_TIME 1 | ||
#define DISPLAY_LEVEL 1 | ||
#define DISPLAY_FUNC 1 | ||
#define DISPLAY_FILE 1 | ||
#define DISPLAY_LINE 1 | ||
#define DISPLAY_BORDER 1 | ||
#define DISPLAY_MESSAGE 1 | ||
#define DISPLAY_ENDING 1 | ||
#define DISPLAY_RESET 1 | ||
#include <spdlog/spdlog.h> | ||
#include <spdlog/sinks/stdout_color_sinks.h> | ||
#include <memory> | ||
#include "spdlog/fmt/fmt.h" | ||
|
||
/* Log to screen */ | ||
#define emit_log(colour, level, file, func, line, ...) do { \ | ||
\ | ||
/* notate the time */ \ | ||
time_t raw_time = time(NULL); \ | ||
char time_buffer[80]; \ | ||
strftime(time_buffer, 80, TIME_FORMAT, localtime(&raw_time)); \ | ||
\ | ||
/* enable colour */ \ | ||
printf("%s", DISPLAY_COLOUR ? colour : ""); \ | ||
\ | ||
/* display the time */ \ | ||
printf("%s%s", DISPLAY_TIME ? time_buffer : "", DISPLAY_TIME ? " " : ""); \ | ||
\ | ||
/* display the level */ \ | ||
printf("%10s%s", DISPLAY_LEVEL ? level : "", DISPLAY_LEVEL ? " " : ""); \ | ||
\ | ||
/* display the function doing the logging */ \ | ||
printf("%s%s", DISPLAY_FUNC ? func : "", DISPLAY_FUNC ? " " : ""); \ | ||
\ | ||
/* display the file and/or the line number */ \ | ||
printf( \ | ||
"%s%s%s%.d%s%s", \ | ||
DISPLAY_FUNC && (DISPLAY_FILE || DISPLAY_LINE) ? "(" : "", \ | ||
DISPLAY_FILE ? file : "", \ | ||
DISPLAY_FILE && DISPLAY_LINE ? ":" : "", \ | ||
DISPLAY_LINE ? line : 0, \ | ||
DISPLAY_FUNC && (DISPLAY_FILE || DISPLAY_LINE) ? ") " : "", \ | ||
!DISPLAY_FUNC && (DISPLAY_FILE || DISPLAY_LINE) ? " " : "" \ | ||
); \ | ||
\ | ||
/* display message border */ \ | ||
printf("%s%s", DISPLAY_BORDER ? BORDER : "", DISPLAY_BORDER ? " " : ""); \ | ||
\ | ||
/* display the callee's message */ \ | ||
if (DISPLAY_MESSAGE) printf(__VA_ARGS__); \ | ||
\ | ||
/* add the message ending (usually '\n') */ \ | ||
printf("%s", DISPLAY_ENDING ? MSG_ENDING : ""); \ | ||
\ | ||
/* reset the colour */ \ | ||
printf("%s", DISPLAY_RESET ? RESET_COLOUR : ""); \ | ||
\ | ||
} while (0) | ||
// Global logger instance | ||
extern std::shared_ptr<spdlog::logger> global_logger; | ||
|
||
/* Level enum */ | ||
#define DEBUG 0 | ||
#define INFO 1 | ||
#define NOTICE 2 | ||
#define WARNING 3 | ||
#define ERROR 4 | ||
#define CRITICAL 5 | ||
#define SILENT 6 | ||
// Custom logging function | ||
void customLog(spdlog::level::level_enum log_level, const char* file, int line, const char* func, const std::string& message); | ||
|
||
/* DEBUG LOG */ | ||
#define log_debug(...) do { \ | ||
if (LOG_LEVEL == DEBUG) { \ | ||
emit_log( \ | ||
DEBUG_COLOUR, "[DEBUG]", __FILE__, __func__, __LINE__, __VA_ARGS__ \ | ||
); \ | ||
} \ | ||
} while (0) | ||
#define log_trace(...) customLog(spdlog::level::trace, __FILE__, __LINE__, __func__, fmt::format(__VA_ARGS__)) | ||
#define log_debug(...) customLog(spdlog::level::debug, __FILE__, __LINE__, __func__, fmt::format(__VA_ARGS__)) | ||
#define log_info(...) customLog(spdlog::level::info, __FILE__, __LINE__, __func__, fmt::format(__VA_ARGS__)) | ||
#define log_notice(...) customLog(spdlog::level::info, __FILE__, __LINE__, __func__, fmt::format(__VA_ARGS__)) | ||
#define log_warning(...) customLog(spdlog::level::warn, __FILE__, __LINE__, __func__, fmt::format(__VA_ARGS__)) | ||
#define log_error(...) customLog(spdlog::level::err, __FILE__, __LINE__, __func__, fmt::format(__VA_ARGS__)) | ||
#define log_critical(...) customLog(spdlog::level::critical, __FILE__, __LINE__, __func__, fmt::format(__VA_ARGS__)) | ||
|
||
/* INFO LOG */ | ||
#define log_info(...) do { \ | ||
if (LOG_LEVEL <= INFO) { \ | ||
emit_log( \ | ||
INFO_COLOUR, "[INFO]", __FILE__, __func__, __LINE__, __VA_ARGS__ \ | ||
); \ | ||
} \ | ||
} while (0) | ||
|
||
/* NOTICE LOG */ | ||
#define log_notice(...) do { \ | ||
if (LOG_LEVEL <= NOTICE) { \ | ||
emit_log( \ | ||
NOTICE_COLOUR, "[NOTICE]", __FILE__, __func__, __LINE__, __VA_ARGS__ \ | ||
); \ | ||
} \ | ||
} while (0) | ||
|
||
/* WARNING LOG */ | ||
#define log_warning(...) do { \ | ||
if (LOG_LEVEL <= WARNING) { \ | ||
emit_log( \ | ||
WARNING_COLOUR, "[WARNING]", __FILE__, __func__, __LINE__, __VA_ARGS__ \ | ||
); \ | ||
} \ | ||
} while (0) | ||
|
||
/* ERROR LOG */ | ||
#define log_error(...) do { \ | ||
if (LOG_LEVEL <= ERROR) { \ | ||
emit_log( \ | ||
ERROR_COLOUR, "[ERROR]", __FILE__, __func__, __LINE__, __VA_ARGS__ \ | ||
); \ | ||
} \ | ||
} while (0) | ||
|
||
/* CRITICAL LOG */ | ||
#define log_critical(...) do { \ | ||
if (LOG_LEVEL <= CRITICAL) { \ | ||
emit_log( \ | ||
CRITICAL_COLOUR, "[CRITICAL]", __FILE__, __func__, __LINE__, __VA_ARGS__\ | ||
); \ | ||
} \ | ||
} while (0) | ||
|
||
#endif | ||
// | ||
#endif | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.