Logger.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <OgreStringConverter.h>
  16. #include "Logger.h"
  17. #include "common/FileSystem.h"
  18. Logger* LOGGER = NULL;
  19. Ogre::String HexToString(int value, unsigned short width, char fill){
  20. std::stringstream stream;
  21. stream.width(width);
  22. stream.fill(fill);
  23. stream.setf(std::ios::hex, std::ios::basefield);
  24. stream << value;
  25. return stream.str();
  26. }
  27. Ogre::String BoolToString(bool value){
  28. return Ogre::StringConverter::toString(value);
  29. }
  30. Ogre::String IntToString(int value){
  31. return Ogre::StringConverter::toString(value);
  32. }
  33. Ogre::String FloatToString(float value){
  34. return Ogre::StringConverter::toString(value);
  35. }
  36. Logger::Logger(const Ogre::String& log_file_name):
  37. log_file_(log_file_name){
  38. FileSystem::RemoveFile(log_file_);
  39. }
  40. Logger::~Logger(){}
  41. void Logger::Log(const Ogre::String& text){
  42. FileSystem::WriteFile(log_file_, text.c_str(), text.size());
  43. }
  44. void Logger::LogW(const Ogre::UTFString& text){
  45. FileSystem::WriteFile(log_file_, text.c_str(), text.size() * 2);
  46. }
  47. void Logger::Log(std::vector< unsigned char >& text){
  48. unsigned char* temp = new unsigned char[ text.size() ];
  49. for (unsigned int i = 0; i < text.size(); ++ i) temp[i] = text[i];
  50. FileSystem::WriteFile(log_file_, temp, text.size());
  51. delete[] temp;
  52. }