trikRuntime
QsLogDest.h
Go to the documentation of this file.
1 // Copyright (c) 2013, Razvan Petru
2 // All rights reserved.
3 
4 // Redistribution and use in source and binary forms, with or without modification,
5 // are permitted provided that the following conditions are met:
6 
7 // * Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright notice, this
10 // list of conditions and the following disclaimer in the documentation and/or other
11 // materials provided with the distribution.
12 // * The name of the contributors may not be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
19 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
24 // OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #pragma once
27 
28 #include "QsLogLevel.h"
29 #include <QSharedPointer>
30 #include <QtGlobal>
31 class QString;
32 class QObject;
33 
34 #ifdef QSLOG_IS_SHARED_LIBRARY
35 #define QSLOG_SHARED_OBJECT Q_DECL_EXPORT
36 #elif defined(QSLOG_IS_SHARED_LIBRARY_IMPORT)
37 #define QSLOG_SHARED_OBJECT Q_DECL_IMPORT
38 #else
39 #define QSLOG_SHARED_OBJECT
40 #endif
41 
42 namespace QsLogging
43 {
44 
46 {
47 public:
48  typedef void (*LogFunction)(const QString &message, Level level);
49 
50 public:
51  virtual ~Destination();
52  virtual void write(const QString& message, Level level) = 0;
53  virtual bool isValid() = 0; // returns whether the destination was created correctly
54 };
55 typedef QSharedPointer<Destination> DestinationPtr;
56 
57 
58 // a series of "named" paramaters, to make the file destination creation more readable
60 {
63 };
64 
66 {
67  MaxSizeBytes() : size(0) {}
68  explicit MaxSizeBytes(qint64 size_) : size(size_) {}
69  qint64 size;
70 };
71 
73 {
74  MaxOldLogCount() : count(0) {}
75  explicit MaxOldLogCount(int count_) : count(count_) {}
76  int count;
77 };
78 
79 
83 {
84 public:
85  static DestinationPtr MakeFileDestination(const QString& filePath,
87  const MaxSizeBytes &sizeInBytesToRotateAfter = MaxSizeBytes(),
88  const MaxOldLogCount &oldLogsToKeep = MaxOldLogCount(),
89  Level level = InfoLevel);
90  static DestinationPtr MakeDebugOutputDestination();
91  // takes a pointer to a function
92  static DestinationPtr MakeFunctorDestination(Destination::LogFunction f);
93  // takes a QObject + signal/slot
94  static DestinationPtr MakeFunctorDestination(QObject *receiver, const char *member);
95 };
96 
97 } // end namespace
MaxSizeBytes()
Definition: QsLogDest.h:67
MaxOldLogCount()
Definition: QsLogDest.h:74
Definition: QsLogDest.h:62
Definition: QsLogLevel.h:35
Definition: QsLogDest.h:61
QSharedPointer< Destination > DestinationPtr
Definition: QsLogDest.h:55
void(* LogFunction)(const QString &message, Level level)
Definition: QsLogDest.h:48
#define QSLOG_SHARED_OBJECT
Definition: QsLogDest.h:39
Definition: QsLogDest.h:72
MaxSizeBytes(qint64 size_)
Definition: QsLogDest.h:68
Level
Definition: QsLogLevel.h:31
LogRotationOption
Definition: QsLogDest.h:59
qint64 size
Definition: QsLogDest.h:69
int count
Definition: QsLogDest.h:76
Definition: QsLogDest.h:45
Creates logging destinations/sinks.
Definition: QsLogDest.h:82
Definition: QsLog.cpp:38
MaxOldLogCount(int count_)
Definition: QsLogDest.h:75
Definition: QsLogDest.h:65