Created
January 31, 2014 12:33
-
-
Save jshbrntt/8731259 to your computer and use it in GitHub Desktop.
Color Logging in Win32
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
#include <Windows.h> | |
#include <cstdio> | |
#include "log.h" | |
#define COLOR_BLACK 0x0 | |
#define COLOR_BLUE 0x1 | |
#define COLOR_GREEN 0x2 | |
#define COLOR_AQUA 0x3 | |
#define COLOR_RED 0x4 | |
#define COLOR_PURPLE 0x5 | |
#define COLOR_YELLOW 0x6 | |
#define COLOR_WHITE 0x7 | |
#define COLOR_GRAY 0x8 | |
#define COLOR_LIGHT_BLUE 0x9 | |
#define COLOR_LIGHT_GREEN 0xA | |
#define COLOR_LIGHT_AQUA 0xB | |
#define COLOR_LIGHT_RED 0xC | |
#define COLOR_LIGHT_PURPLE 0xD | |
#define COLOR_LIGHT_YELLOW 0xE | |
#define COLOR_BRIGHT_WHITE 0xF | |
#define COLOR_DEFAULT COLOR_WHITE | |
namespace Log | |
{ | |
HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE); | |
void black(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_BLACK); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void blue(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_BLUE); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void green(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_GREEN); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void aqua(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_AQUA); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void red(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_RED); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void purple(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_PURPLE); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void yellow(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_YELLOW); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void white(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_WHITE); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void gray(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_GRAY); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void lightBlue(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_LIGHT_BLUE); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void lightGreen(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_LIGHT_GREEN); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void lightAqua(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_LIGHT_AQUA); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void lightRed(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_LIGHT_RED); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void lightPurple(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_LIGHT_PURPLE); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void lightYellow(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_LIGHT_YELLOW); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void brightWhite(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_BRIGHT_WHITE); | |
vfprintf(stdout, format, args); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
va_end(args); | |
} | |
void default(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
SetConsoleTextAttribute(output, COLOR_DEFAULT); | |
vfprintf(stdout, format, args); | |
va_end(args); | |
} | |
// WINDOW: | |
void windowReshaped(int width, int height, float ratio) | |
{ | |
window(); | |
lightAqua("W: "); Log::white("%i ", width); | |
lightAqua("H: "); Log::white("%i ", height); | |
lightAqua("R: "); Log::white("%f\n", ratio); | |
} | |
// SHADER: | |
void shaderLoaded(const char *filePath) | |
{ | |
shader(); | |
loaded(); | |
default("%s\n", filePath); | |
} | |
void shaderMissing(const char *filePath) | |
{ | |
shader(); | |
missing(); | |
default("%s\n", filePath); | |
} | |
void shaderFailed(const char *filePath, std::string errors) | |
{ | |
shader(); | |
failed(); | |
default("%s\n%s", filePath, errors.c_str()); | |
} | |
// OBJ: | |
void objLoaded(const char *filePath) | |
{ | |
obj(); | |
loaded(); | |
default("%s\n", filePath); | |
} | |
void objMissing(const char *filePath) | |
{ | |
obj(); | |
missing(); | |
default("%s\n", filePath); | |
} | |
void objFailed(const char *filePath) | |
{ | |
obj(); | |
failed(); | |
default("%s\n", filePath); | |
} | |
// COLORMAP: | |
void colorMapLoaded(const char *filePath) | |
{ | |
colorMap(); | |
loaded(); | |
default("%s\n", filePath); | |
} | |
void colorMapMissing(const char *filePath) | |
{ | |
colorMap(); | |
missing(); | |
default("%s\n", filePath); | |
} | |
void colorMapFailed(const char *filePath) | |
{ | |
colorMap(); | |
failed(); | |
default("%s\n", filePath); | |
} | |
// BUMPMAP: | |
void bumpMapLoaded(const char *filePath) | |
{ | |
bumpMap(); | |
loaded(); | |
default("%s\n", filePath); | |
} | |
void bumpMapMissing(const char *filePath) | |
{ | |
bumpMap(); | |
missing(); | |
default("%s\n", filePath); | |
} | |
void bumpMapFailed(const char *filePath) | |
{ | |
bumpMap(); | |
failed(); | |
default("%s\n", filePath); | |
} | |
void window() { aqua( "[WINDOW] "); } | |
void shader() { yellow( "[SHADER] "); } | |
void obj() { red( "[OBJ] "); } | |
void colorMap() { green( "[COLOR-MAP] "); } | |
void bumpMap() { blue( "[BUMP-MAP] "); } | |
void loaded() { lightGreen( "[LOADED] "); } | |
void failed() { lightRed( "[FAILED] "); } | |
void missing() { lightYellow("[MISSING] "); } | |
} |
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
#ifndef LOG_H | |
#define LOG_H | |
#include <string> | |
namespace Log | |
{ | |
// STYLING: | |
void black(const char * format, ...); | |
void blue(const char * format, ...); | |
void green(const char * format, ...); | |
void aqua(const char * format, ...); | |
void red(const char * format, ...); | |
void purple(const char * format, ...); | |
void yellow(const char * format, ...); | |
void white(const char * format, ...); | |
void gray(const char * format, ...); | |
void lightBlue(const char * format, ...); | |
void lightGreen(const char * format, ...); | |
void lightAqua(const char * format, ...); | |
void lightRed(const char * format, ...); | |
void lightPurple(const char * format, ...); | |
void lightYellow(const char * format, ...); | |
void brightWhite(const char * format, ...); | |
void default(const char * format, ...); | |
// WINDOW: | |
void windowReshaped(int width, int height, float ratio); | |
// SHADER: | |
void shaderLoaded(const char *filePath); | |
void shaderMissing(const char *filePath); | |
void shaderFailed(const char *filePath, std::string errors); | |
// OBJ: | |
void objLoaded(const char *filePath); | |
void objMissing(const char *filePath); | |
void objFailed(const char *filePath); | |
// COLORMAP: | |
void colorMapLoaded(const char *filePath); | |
void colorMapMissing(const char *filePath); | |
void colorMapFailed(const char *filePath); | |
// BUMPMAP: | |
void bumpMapLoaded(const char *filePath); | |
void bumpMapMissing(const char *filePath); | |
void bumpMapFailed(const char *filePath); | |
// TYPES: | |
void window(); | |
void shader(); | |
void obj(); | |
void colorMap(); | |
void bumpMap(); | |
// STATUS: | |
void loaded(); | |
void failed(); | |
void missing(); | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good job!