header only\!
This commit is contained in:
		@@ -20,3 +20,24 @@ private:
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
inline c11log::details::factory::logger_ptr c11log::details::factory::get_logger(const std::string &name)
 | 
			
		||||
{
 | 
			
		||||
	std::lock_guard<std::mutex> lock(_loggers_mutex);
 | 
			
		||||
	auto found = _loggers.find(name);
 | 
			
		||||
	if (found == _loggers.end()) {
 | 
			
		||||
		auto new_logger_ptr = std::make_shared<c11log::logger>(name);
 | 
			
		||||
		_loggers.insert(std::make_pair(name, new_logger_ptr));
 | 
			
		||||
		return new_logger_ptr;
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
		return found->second;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
inline c11log::details::factory & c11log::details::factory::instance()
 | 
			
		||||
{
 | 
			
		||||
	static c11log::details::factory instance;
 | 
			
		||||
	return instance;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,9 +9,28 @@ namespace c11log
 | 
			
		||||
	{
 | 
			
		||||
		namespace os
 | 
			
		||||
		{			
 | 
			
		||||
			std::tm localtime(const std::time_t &time_t);			
 | 
			
		||||
			std::tm localtime(const std::time_t &time_tt);
 | 
			
		||||
			std::tm localtime(); 
 | 
			
		||||
			
 | 
			
		||||
		}		
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
inline std::tm c11log::details::os::localtime(const std::time_t &time_tt)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    std::tm tm;
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
    localtime_s(&tm, &time_tt);
 | 
			
		||||
#else
 | 
			
		||||
	localtime_r(&time_tt, &tm);
 | 
			
		||||
#endif
 | 
			
		||||
    return tm;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
inline std::tm c11log::details::os::localtime()
 | 
			
		||||
{
 | 
			
		||||
    std::time_t now_t = time(0);
 | 
			
		||||
    return localtime(now_t);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -39,3 +39,27 @@ private:
 | 
			
		||||
};
 | 
			
		||||
} //namespace formatter
 | 
			
		||||
} //namespace c11log
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
inline void c11log::formatters::default_formatter::_format_time(const time_point& tp, std::ostream &dest)
 | 
			
		||||
{
 | 
			
		||||
    using namespace std::chrono;
 | 
			
		||||
 | 
			
		||||
	static thread_local c11log::formatters::time_point last_tp;
 | 
			
		||||
	static thread_local char timestamp_cache[64];
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	if(duration_cast<milliseconds>(tp-last_tp).count() > 950)
 | 
			
		||||
    {
 | 
			
		||||
    	auto tm = details::os::localtime(clock::to_time_t(tp));
 | 
			
		||||
		sprintf(timestamp_cache, "[%d-%02d-%02d %02d:%02d:%02d]", tm.tm_year + 1900,
 | 
			
		||||
			tm.tm_mon + 1,
 | 
			
		||||
			tm.tm_mday,
 | 
			
		||||
			tm.tm_hour,
 | 
			
		||||
			tm.tm_min,
 | 
			
		||||
			tm.tm_sec);
 | 
			
		||||
		last_tp = tp;
 | 
			
		||||
    }
 | 
			
		||||
	dest << timestamp_cache;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -164,3 +164,4 @@ inline c11log::logger& c11log::get_logger(const std::string& name)
 | 
			
		||||
{
 | 
			
		||||
	return *(c11log::details::factory::instance().get_logger(name));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -90,7 +90,6 @@ private:
 | 
			
		||||
		}
 | 
			
		||||
		_ofstream.open(_calc_filename(_base_filename, 0, _extension));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	std::string _base_filename;
 | 
			
		||||
	std::string _extension;
 | 
			
		||||
	std::size_t _max_size;
 | 
			
		||||
@@ -98,7 +97,6 @@ private:
 | 
			
		||||
	std::size_t _current_size;
 | 
			
		||||
	std::mutex mutex_;
 | 
			
		||||
	std::ofstream _ofstream;
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user