Created
August 29, 2018 00:28
-
-
Save alifahrri/d26e3910727d3db7fb2b6812483615bb to your computer and use it in GitHub Desktop.
i need to log something,
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 LOGGER_HPP | |
#define LOGGER_HPP | |
#include <string> | |
#include <iostream> | |
#include <fstream> | |
#include <sstream> | |
class Logger | |
{ | |
public: | |
Logger() {} | |
std::string str() | |
{ | |
return ss.str(); | |
} | |
void log(std::string msg) | |
{ | |
ss << msg; | |
} | |
template <typename Class> | |
void log(std::string label, Class value) | |
{ | |
ss << label << value << std::endl; | |
} | |
void clear() | |
{ | |
ss.str() = std::string(); | |
} | |
void print() | |
{ | |
std::cout << ss.str() << std::flush; | |
} | |
void save(std::string filename) | |
{ | |
std::fstream writer(filename); | |
writer << ss.str(); | |
writer.close(); | |
} | |
private: | |
std::stringstream ss; | |
}; | |
#endif // LOGGER_HPP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment