Skip to content

Instantly share code, notes, and snippets.

@milesrout
Last active August 29, 2015 14:08
Show Gist options
  • Save milesrout/0a020b59ef61f7616060 to your computer and use it in GitHub Desktop.
Save milesrout/0a020b59ef61f7616060 to your computer and use it in GitHub Desktop.
namespace trillek {
namespace util {
namespace logging {
namespace detail {
std::unique_ptr<logger> global_logger;
}
}
}
}
#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 */
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