Created
July 24, 2023 02:37
-
-
Save TheFlash2k/a32b2b1ffac86afe9faca844a9a6b0d9 to your computer and use it in GitHub Desktop.
possibly the most simplest log2cli macros. (with colors too :))))
This file contains hidden or 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
#define _CRT_SECURE_NO_WARNINGS | |
#include <stdio.h> | |
#include <time.h> | |
#pragma warning (disable : 4005) | |
#pragma warning (disable : 4172) // Line 22 | |
#define TIME_BUFFER_SIZE 20 | |
char timeBuffer[TIME_BUFFER_SIZE]; | |
void gettime() { | |
time_t currentTime; | |
struct tm* timeInfo; | |
time(¤tTime); | |
timeInfo = localtime(¤tTime); | |
strftime(timeBuffer, TIME_BUFFER_SIZE, "%d/%m/%Y-%H:%M:%S", timeInfo); | |
} | |
#define base(file, method, msg, ...) {\ | |
gettime();\ | |
fprintf(file, "[\033[36m%s\033[0m] [%s] [\033[32m%s\033[0m:\033[31m%d\033[0m] ", timeBuffer, method, __FUNCTION__, __LINE__);\ | |
fprintf(file, msg, __VA_ARGS__);\ | |
fprintf(file, "\n");\ | |
} | |
#define Log(x, ...) {\ | |
base(stdout, "\033[32mLOG\033[0m", x, __VA_ARGS__)\ | |
} | |
#define Error(x, ...) {\ | |
base(stdout, "\033[31mERROR\033[0m", x, __VA_ARGS__)\ | |
} | |
#define Info(x, ...) {\ | |
base(stdout, "\033[34mINFO\033[0m", x, __VA_ARGS__)\ | |
} | |
#define Warn(x, ...) {\ | |
base(stdout, "\033[33mWARNING\033[0m", x, __VA_ARGS__)\ | |
} | |
#define Debug(x, ...) {\ | |
base(stdout, "\033[35mDEBUG\033[0m", x, __VA_ARGS__)\ | |
} | |
#define MSG(x, ...) {\ | |
printf(x, __VA_ARGS__);\ | |
printf("\n");\ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment