Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS // For Windows-Users (ctime gets warnings) - all other can delete or ignore this line
- #include <ctime>
- #include "logger.hpp"
- #include "policy.hpp"
- #include "consolepolicy.hpp"
- using namespace std;
- /// \brief Helper function to get a time-string with second resolution.
- static std::string getTimeString()
- {
- std::string timeStr;
- time_t rawTime;
- time( &rawTime );
- timeStr = ctime( &rawTime );
- return timeStr.substr( 0 , timeStr.size() - 1 );
- }
- void Logger::write(const std::string & file, long line, const std::string & message)
- {
- if (_cpolicies == NULL) {
- m_history = m_history + file + " " + to_string(line) + " " + message + " " + getTimeString();
- m_history += "\n";
- }
- else
- {
- std::string logtxt = file + " " + to_string(line) + " " + message + " " + getTimeString() + "\n";;
- _cpolicies->write(logtxt);
- }
- }
- void Logger::registerPolicy(std::unique_ptr<Policy> _policy)
- {
- if (_cpolicies == NULL) {
- _cpolicies = std::move(_policy);
- _cpolicies->write(m_history);
- }
- else
- {
- _cpolicies = std::move(_policy);
- }
- }
- Logger & Logger::instance()
- {
- static Logger theOneAndOnly;
- return theOneAndOnly;
- // TODO: hier Rückgabeanweisung eingeben
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement