QsLogDestFunctor.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (c) 2014, Razvan Petru
  2. // Copyright (c) 2014, Omar Carey
  3. // All rights reserved.
  4. // Redistribution and use in source and binary forms, with or without modification,
  5. // are permitted provided that the following conditions are met:
  6. // * Redistributions of source code must retain the above copyright notice, this
  7. // list of conditions and the following disclaimer.
  8. // * Redistributions in binary form must reproduce the above copyright notice, this
  9. // list of conditions and the following disclaimer in the documentation and/or other
  10. // materials provided with the distribution.
  11. // * The name of the contributors may not be used to endorse or promote products
  12. // derived from this software without specific prior written permission.
  13. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  17. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  21. // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  22. // OF THE POSSIBILITY OF SUCH DAMAGE.
  23. #ifndef QSLOGDESTFUNCTOR_H
  24. #define QSLOGDESTFUNCTOR_H
  25. #include "QsLogDest.h"
  26. #include <QObject>
  27. namespace QsLogging
  28. {
  29. // Offers various types of function-like sinks.
  30. // This is an advanced destination type. Depending on your configuration, LogFunction might be
  31. // called from a different thread or even a different binary. You should not access QsLog from
  32. // inside LogFunction and should not perform any time-consuming operations.
  33. // logMessageReady is connected through a queued connection and trace messages are not included
  34. class FunctorDestination : public QObject, public Destination
  35. {
  36. Q_OBJECT
  37. public:
  38. explicit FunctorDestination(LogFunction f);
  39. FunctorDestination(QObject *receiver, const char *member);
  40. virtual void write(const QString &message, Level level);
  41. virtual bool isValid();
  42. virtual void rotate() { }
  43. protected:
  44. // int used to avoid registering a new enum type
  45. Q_SIGNAL void logMessageReady(const QString &message, int level);
  46. private:
  47. LogFunction mLogFunction;
  48. };
  49. }
  50. #endif // QSLOGDESTFUNCTOR_H