juce_Logger.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. ==============================================================================
  3. This file is part of the juce_core module of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. or without fee is hereby granted, provided that the above copyright notice and this
  7. permission notice appear in all copies.
  8. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  9. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  10. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  11. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  12. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. ------------------------------------------------------------------------------
  15. NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
  16. All other JUCE modules are covered by a dual GPL/commercial license, so if you are
  17. using any other modules, be sure to check that you also comply with their license.
  18. For more details, visit www.juce.com
  19. ==============================================================================
  20. */
  21. #ifndef JUCE_LOGGER_H_INCLUDED
  22. #define JUCE_LOGGER_H_INCLUDED
  23. //==============================================================================
  24. /**
  25. Acts as an application-wide logging class.
  26. A subclass of Logger can be created and passed into the Logger::setCurrentLogger
  27. method and this will then be used by all calls to writeToLog.
  28. The logger class also contains methods for writing messages to the debugger's
  29. output stream.
  30. @see FileLogger
  31. */
  32. class JUCE_API Logger
  33. {
  34. public:
  35. //==============================================================================
  36. /** Destructor. */
  37. virtual ~Logger();
  38. //==============================================================================
  39. /** Sets the current logging class to use.
  40. Note that the object passed in will not be owned or deleted by the logger, so
  41. the caller must make sure that it is not deleted while still being used.
  42. A null pointer can be passed-in to disable any logging.
  43. */
  44. static void JUCE_CALLTYPE setCurrentLogger (Logger* newLogger) noexcept;
  45. /** Returns the current logger, or nullptr if none has been set. */
  46. static Logger* getCurrentLogger() noexcept;
  47. /** Writes a string to the current logger.
  48. This will pass the string to the logger's logMessage() method if a logger
  49. has been set.
  50. @see logMessage
  51. */
  52. static void JUCE_CALLTYPE writeToLog (const String& message);
  53. //==============================================================================
  54. /** Writes a message to the standard error stream.
  55. This can be called directly, or by using the DBG() macro in
  56. juce_PlatformDefs.h (which will avoid calling the method in non-debug builds).
  57. */
  58. static void JUCE_CALLTYPE outputDebugString (const String& text);
  59. protected:
  60. //==============================================================================
  61. Logger();
  62. /** This is overloaded by subclasses to implement custom logging behaviour.
  63. @see setCurrentLogger
  64. */
  65. virtual void logMessage (const String& message) = 0;
  66. private:
  67. static Logger* currentLogger;
  68. };
  69. #endif // JUCE_LOGGER_H_INCLUDED