Skip to content

Instantly share code, notes, and snippets.

@alifahrri
Created August 29, 2018 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alifahrri/d26e3910727d3db7fb2b6812483615bb to your computer and use it in GitHub Desktop.
Save alifahrri/d26e3910727d3db7fb2b6812483615bb to your computer and use it in GitHub Desktop.
i need to log something,
#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