|
|
- /*
- * Log.cpp
- *
- * Created on: 16.01.2017
- * Author: piotrek
- */
-
- #include "Log.h"
-
- Log::Log()
- {
- this->color = WHITE;
- this->delimiter = "";
- this->lineNumber = 0;
- this->objectName = NULL;
-
- this->writeMutex = Log::getMutex();
- }
-
- LOG_COLOR Log::getColor() const
- {
- return color;
- }
-
- void Log::setColor(LOG_COLOR color)
- {
- this->color = color;
- }
-
- const string& Log::getDelimiter() const
- {
- return delimiter;
- }
-
- void Log::setDelimiter(const string& delimiter)
- {
- this->delimiter = delimiter;
- }
-
- int Log::getLineNumber() const
- {
- return lineNumber;
- }
-
- void Log::setLineNumber(int lineNumber)
- {
- this->lineNumber = lineNumber;
- }
-
- string* Log::getObjectName() const
- {
- return objectName;
- }
-
- void Log::setObjectName(string* objectName)
- {
- this->objectName = objectName;
- }
-
- void Log::print(string msg)
- {
- #ifndef DEBUG
- if (this->getObjectName() == NULL)
- return;
-
- pthread_mutex_lock(this->writeMutex);
- move(this->getLineNumber(), 0);
- clrtoeol();
-
- if(has_colors())
- attron(COLOR_PAIR(this->getColor()));
-
- printw("%s:%s%s", this->getObjectName()->c_str(), this->getDelimiter().c_str(), msg.c_str());
-
- if(has_colors())
- attroff(COLOR_PAIR(this->getColor()));
-
- move(0, 0);
- pthread_mutex_unlock(this->writeMutex);
-
- #else
- cout << this->getObjectName()->c_str() << ": " << this->getDelimiter() << msg << endl;
- #endif
- }
-
- void Log::setLogParams(int lineNumber, LOG_COLOR color, string delimiter)
- {
- this->setLineNumber(lineNumber);
- this->setColor(color);
- this->setDelimiter(delimiter);
- }
-
- pthread_mutex_t* Log::getMutex()
- {
- static pthread_mutex_t m;
- static int mutex_initalized;
- if (mutex_initalized != 0)
- {
- pthread_mutex_init(&m, NULL);
- }
-
- return &m;
- }
|