Symulacja NAT na przedmiot Symulacje Komputerowe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.4 KiB

  1. /*
  2. * Log.cpp
  3. *
  4. * Created on: 16.01.2017
  5. * Author: piotrek
  6. */
  7. #include "Log.h"
  8. Log::Log()
  9. {
  10. this->color = WHITE;
  11. this->delimiter = "";
  12. this->lineNumber = 0;
  13. this->objectName = NULL;
  14. }
  15. LOG_COLOR Log::getColor() const
  16. {
  17. return color;
  18. }
  19. void Log::setColor(LOG_COLOR color)
  20. {
  21. this->color = color;
  22. }
  23. const string& Log::getDelimiter() const
  24. {
  25. return delimiter;
  26. }
  27. void Log::setDelimiter(const string& delimiter)
  28. {
  29. this->delimiter = delimiter;
  30. }
  31. int Log::getLineNumber() const
  32. {
  33. return lineNumber;
  34. }
  35. void Log::setLineNumber(int lineNumber)
  36. {
  37. this->lineNumber = lineNumber;
  38. }
  39. string* Log::getObjectName() const
  40. {
  41. return objectName;
  42. }
  43. void Log::setObjectName(string* objectName)
  44. {
  45. this->objectName = objectName;
  46. }
  47. void Log::print(string msg)
  48. {
  49. #ifndef DEBUG
  50. if (this->getObjectName() == NULL)
  51. return;
  52. move(this->getLineNumber(), 0);
  53. clrtoeol();
  54. if(has_colors())
  55. attron(COLOR_PAIR(this->getColor()));
  56. printw("%s:%s%s", this->getObjectName()->c_str(), this->getDelimiter().c_str(), msg.c_str());
  57. if(has_colors())
  58. attroff(COLOR_PAIR(this->getColor()));
  59. move(0, 0);
  60. #else
  61. cout << this->getObjectName()->c_str() << ": " << this->getDelimiter() << msg << endl;
  62. #endif
  63. }
  64. void Log::setLogParams(int lineNumber, LOG_COLOR color, string delimiter)
  65. {
  66. this->setLineNumber(lineNumber);
  67. this->setColor(color);
  68. this->setDelimiter(delimiter);
  69. }