I'm trying to build a simple log system, but I've met a problem with my concept:
class logger_instance
{
std::string log_file;
std::string log_type;
std::ofstream log;
public:
logger_instance(std::string log_type) : log_type(log_type), log_file("logs\\" + log_type + ".log"), log(log_file)
{
operator << ("logger_instance(" + log_type + ") init.\n");
}
std::string get_log_type() const
{
return log_type;
}
std::string get_log_file() const
{
return log_file;
}
logger_instance& operator << (std::string message)
{
time_t current_time;
time(¤t_time);
log << ctime(¤t_time);
log << " : ";
log << message;
log << "\n";
}
};
class logger_manager
{
std::map < std::string, logger_instance > loggers;
public:
void add_logger(std::string logger)
{
auto it = loggers.find(logger);
if (it == loggers.end())
{
loggers.emplace(logger, logger);
}
}
logger_instance& operator[](std::string logger)
{
return loggers[logger];
}
};
Compiler : Visual Studio 2013 Update 4
The problem which I'm encountering is that the emplace function doesn't seem to understand that I want the logger_instance object to be built on-the-spot, in the map container. Given the fact that I'm not smarter than a compiler, the problem is in my concept, but I'm unable to find a solution.
Aucun commentaire:
Enregistrer un commentaire