-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
13 changed files
with
423 additions
and
726 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
# Editor | ||
.vscode/ | ||
.vs/ | ||
*.sln | ||
*.vcxproj | ||
*.vcxproj.* | ||
|
||
# Output | ||
bin/ | ||
bin-int/ | ||
|
||
# Prerequisites | ||
*.d | ||
|
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
call premake5.exe vs2019 | ||
pause |
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,2 +1,24 @@ | ||
# logtools | ||
A cross-platform logging toolset | ||
A small and simple cross-platform logging toolset. | ||
|
||
## Features | ||
|
||
- Easy logging | ||
- Cross-platform for Windows and Linux | ||
|
||
## Get started | ||
|
||
Please note: currently the library is made with C++17 in mind, as that is the main C++ version I'm using for my new projects right now. | ||
|
||
- Go to the [releases](https://github.com/SeppahBaws/logtools/releases) tab and download the latest version of the library. | ||
It should only be a single file called logtools.h | ||
|
||
- Include `logtools.h` in your project | ||
|
||
- At the start of your program, call `Logger::Init();` to initialize the logger. | ||
|
||
- Then you can use the other functions that the Logger provides: `Log(LogLevel, msg)`, `LogInfo(msg)`, `LogWarning(msg)`, `LogError(msg)` | ||
|
||
## Issues | ||
|
||
If you have any troubles setting up or using this library, please create an issue [here](https://github.com/SeppahBaws/logtools/issues/new) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,183 @@ | ||
/* | ||
* LogTools // v1.0 // small and simple cross-platform logging toolset. | ||
* ************ https://github.com/SeppahBaws/logtools ************ | ||
* | ||
* -----------------------------[ LICENSE ]----------------------------- | ||
MIT License | ||
Copyright (c) 2020 Seppe Dekeyser | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
* -----------------------------[ END LICENSE ]----------------------------- | ||
* | ||
* ----- HOW TO USE ----- | ||
Simply include logtools.h into your project. | ||
Initialize the logger by calling | ||
Logger::Init(); | ||
Then you can use the logging functions like this: | ||
Logger::Log(LogLevel::Info, "Hello World"); | ||
or you can use the other logging functions: | ||
Logger::LogInfo("Hello Info"); | ||
Logger::LogWarning("Hello Warning"); | ||
Logger::LogError("Hello Error"); | ||
* ----- END HOW TO ----- | ||
* | ||
* For more info you can check out the README. | ||
* | ||
*/ | ||
|
||
#ifndef INCLUDE_LOGTOOLS_H | ||
#define INCLUDE_LOGTOOLS_H | ||
|
||
// Check if C++17 or greater, by checking if we have a C++17 specific feature. | ||
#if __cpp_inline_variables < 201606 | ||
#error Incorrect C++ version. Logtools requires C++ version 17 or greater. | ||
#endif | ||
|
||
////////////////// Colors ////////////////// | ||
#if defined(__linux__) | ||
// Linux Colors | ||
|
||
#define BLACK "\033[30m" | ||
#define RED "\033[31m" | ||
#define GREEN "\033[32m" | ||
#define YELLOW "\033[33m" | ||
#define BLUE "\033[34m" | ||
#define MAGENTA "\033[35m" | ||
#define CYAN "\033[36m" | ||
#define WHITE "\033[37m" | ||
|
||
#define RESET "\033[0m" | ||
|
||
#elif defined(_WIN32) || defined(_WIN64) | ||
// Windows Colors | ||
|
||
#define WIN32_LEAN_AND_MEAN | ||
#include <Windows.h> | ||
|
||
#define BLACK 0 | ||
#define RED FOREGROUND_INTENSITY | FOREGROUND_RED | ||
#define GREEN FOREGROUND_INTENSITY | FOREGROUND_GREEN | ||
#define YELLOW FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | ||
#define BLUE FOREGROUND_INTENSITY | FOREGROUND_BLUE | ||
#define MAGENTA FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | ||
#define CYAN FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE | ||
#define WHITE FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | ||
|
||
#define RESET FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | ||
|
||
#endif | ||
|
||
//////////////// Main Logger //////////////// | ||
#include <string> | ||
#include <iostream> | ||
|
||
enum LogLevel | ||
{ | ||
Info = 0x1, | ||
Warning = 0x2, | ||
Error = 0x4 | ||
}; | ||
|
||
class Logger | ||
{ | ||
public: | ||
static void Init() | ||
{ | ||
#if defined(_WIN32) || defined(_WIN64) | ||
hConsole = GetStdHandle(STD_OUTPUT_HANDLE); | ||
#endif | ||
} | ||
|
||
static void Log(LogLevel level, const std::string& msg) | ||
{ | ||
switch (level) | ||
{ | ||
case LogLevel::Info: | ||
LogInfo(msg); | ||
break; | ||
|
||
case LogLevel::Warning: | ||
LogWarning(msg); | ||
break; | ||
|
||
case LogLevel::Error: | ||
LogError(msg); | ||
break; | ||
} | ||
} | ||
|
||
static void LogInfo(const std::string& msg) | ||
{ | ||
LogColor("[INFO] " + msg, WHITE); | ||
} | ||
|
||
static void LogWarning(const std::string& msg) | ||
{ | ||
LogColor("[WARNING] " + msg, YELLOW); | ||
} | ||
|
||
static void LogError(const std::string& msg) | ||
{ | ||
LogColor("[ERROR] " + msg, RED); | ||
} | ||
|
||
private: | ||
#if defined(__linux__) | ||
// Linux specific | ||
static void ResetConsoleColors() | ||
{ | ||
std::cout << RESET; | ||
} | ||
static void LogColor(const std::string& msg, const std::string& color) | ||
{ | ||
std::cout << color << msg << std::endl; | ||
ResetConsoleColors(); | ||
} | ||
#elif defined(_WIN32) || defined(_WIN64) | ||
// Windows specific | ||
static void ResetConsoleColors() | ||
{ | ||
SetConsoleTextAttribute(Instance().hConsole, RESET); | ||
} | ||
static void LogColor(const std::string& msg, const int color) | ||
{ | ||
SetConsoleTextAttribute(Instance().hConsole, color); | ||
std::cout << msg << std::endl; | ||
ResetConsoleColors(); | ||
} | ||
#endif | ||
|
||
static Logger Instance() | ||
{ | ||
static Logger instance{}; | ||
return instance; | ||
} | ||
|
||
private: | ||
#if defined(_WIN32) || defined(_WIN64) | ||
inline static HANDLE hConsole; | ||
#endif | ||
}; | ||
|
||
#endif INCLUDE_LOGTOOLS_H |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#if defined(__linux__) | ||
// Linux Colors | ||
|
||
#define BLACK "\033[30m" | ||
#define RED "\033[31m" | ||
#define GREEN "\033[32m" | ||
#define YELLOW "\033[33m" | ||
#define BLUE "\033[34m" | ||
#define MAGENTA "\033[35m" | ||
#define CYAN "\033[36m" | ||
#define WHITE "\033[37m" | ||
|
||
#define RESET "\033[0m" | ||
|
||
#elif defined(_WIN32) || defined(_WIN64) | ||
// Windows Colors | ||
|
||
#define WIN32_LEAN_AND_MEAN | ||
#include <Windows.h> | ||
|
||
#define BLACK 0 | ||
#define RED FOREGROUND_INTENSITY | FOREGROUND_RED | ||
#define GREEN FOREGROUND_INTENSITY | FOREGROUND_GREEN | ||
#define YELLOW FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | ||
#define BLUE FOREGROUND_INTENSITY | FOREGROUND_BLUE | ||
#define MAGENTA FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | ||
#define CYAN FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE | ||
#define WHITE FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | ||
|
||
#define RESET FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | ||
|
||
#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.