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