Last active
August 29, 2015 14:08
-
-
Save milesrout/0a020b59ef61f7616060 to your computer and use it in GitHub Desktop.
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
namespace trillek { | |
namespace util { | |
namespace logging { | |
namespace detail { | |
std::unique_ptr<logger> global_logger; | |
} | |
} | |
} | |
} |
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
#ifndef LOGGING_HPP_INCLUDED | |
#define LOGGING_HPP_INCLUDED | |
#include <fstream> | |
#include <iostream> | |
#include <string> | |
#ifndef STRINGIFY | |
#define STRINGIFY(x) #x | |
#define TO_STRING(x) STRINGIFY(x) | |
#endif | |
#define LOG_LEVEL(lvl, message) ::trillek::util::logging::log(lvl, std::string(message) + "\t" __FILE__ ":" TO_STRING(__LINE__)) | |
#define LOG(message) LOG_LEVEL(level::notice, message) | |
#define WARN(message) LOG_LEVEL(level::warning, message) | |
#define ERROR(message) LOG_LEVEL(level::error, message) | |
namespace trillek { | |
namespace util { | |
namespace logging { | |
enum class level { | |
notice, warning, error | |
} | |
void init(std::string filename) | |
{ | |
detail::global_logger = std::make_unique<detail::logger>(filename); | |
} | |
namespace detail { | |
class logger { | |
public: | |
logger(std::string filename); | |
void log(level lvl, std::string message); | |
private: | |
std::ofstream file; | |
}; | |
} | |
} | |
} | |
} | |
#endif /* LOGGING_HPP_INCLUDED */ |
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
int main() | |
{ | |
// whatever | |
::trillek::util::logging::init("trillek.log"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment