PolyLogger.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyEventDispatcher.h"
  22. namespace Polycode {
  23. class _PolyExport LoggerEvent : public Event {
  24. public:
  25. LoggerEvent(String message);
  26. virtual ~LoggerEvent();
  27. String message;
  28. };
  29. /**
  30. * Logs information to the console, should only be called through Logger::
  31. */
  32. class _PolyExport Logger : public EventDispatcher {
  33. public:
  34. /**
  35. * Default constructor
  36. */
  37. Logger();
  38. virtual ~Logger();
  39. /**
  40. * Dispatches LoggerEvent and calls Logger::log()
  41. * @param message String to log
  42. */
  43. void logBroadcast(String message);
  44. /**
  45. * Logs information to the console or debug window of VS (only available if compiled as debug)
  46. * @param format c-strings to log, put the params into the first using the formatting of printf (reference: http://www.cplusplus.com/reference/cstdio/printf/)
  47. */
  48. static void log(const char *format, ...);
  49. /**
  50. * Logs information through wcout
  51. * @param str The c-string to log
  52. */
  53. static void logw(const char *str);
  54. void setLogToFile(bool val);
  55. bool getLogToFile();
  56. /**
  57. * @return The file that is logged to
  58. */
  59. FILE *getLogFile();
  60. /**
  61. * @return The logger instance
  62. */
  63. static Logger *getInstance();
  64. protected:
  65. FILE *logFile;
  66. bool logToFile;
  67. private:
  68. static Logger *overrideInstance;
  69. };
  70. }