ctkCMLogTracker_p.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKCMLOGTRACKER_P_H
  16. #define CTKCMLOGTRACKER_P_H
  17. #include <ctkServiceTracker.h>
  18. #include <service/log/ctkLogService.h>
  19. /**
  20. * This class encapsulates the ctkLogService
  21. * and handles all issues such as the service coming and going.
  22. */
  23. class ctkCMLogTracker : public ctkServiceTracker<ctkLogService*>, public ctkLogService
  24. {
  25. public:
  26. /**
  27. * Create new ctkCMLogTracker.
  28. *
  29. * @param context ctkPluginContext of parent plugin.
  30. * @param out Default QIODevice to use if ctkLogService is unavailable.
  31. */
  32. ctkCMLogTracker(ctkPluginContext* context, QIODevice* out);
  33. /*
  34. * ----------------------------------------------------------------------
  35. * LogService Interface implementation
  36. * ----------------------------------------------------------------------
  37. */
  38. void log(int level, const QString& message, const std::exception* exception = 0,
  39. const char* file = 0, const char* function = 0, int line = -1);
  40. void log(const ctkServiceReference& sr, int level, const QString& message,
  41. const std::exception* exception = 0,
  42. const char* file = 0, const char* function = 0, int line = -1);
  43. int getLogLevel() const;
  44. protected:
  45. ctkLogService* addingService(const ctkServiceReference& reference);
  46. void removedService(const ctkServiceReference& reference, ctkLogService* service);
  47. private:
  48. void logToAll(const ctkServiceReference& reference, int level, const QString& message,
  49. const std::exception* exception, const char* file, const char* function, int line);
  50. /**
  51. * The ctkLogService is not available so we write the message to a QTextStream.
  52. *
  53. * @param reference ctkServiceReference associated with message or a default constructed one if none.
  54. * @param level Logging level.
  55. * @param message Log message.
  56. * @param exc Log exception or null if none.
  57. * @param file The file name where the log message came from.
  58. * @param function The function where the log message came from.
  59. * @param The line number where the log message came from.
  60. */
  61. void noLogService(const ctkServiceReference& reference, int level, const QString& message,
  62. const std::exception* exc, const char* file, const char* function, int line);
  63. /** Output device to use if ctkLogService is unavailable */
  64. QTextStream out;
  65. QMutex mutex;
  66. int logLevel;
  67. };
  68. #endif // CTKCMLOGTRACKER_P_H