Projekt

Obecné

Profil

Stáhnout (3.47 KB) Statistiky
| Větev: | Tag: | Revize:
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
#ifndef QSLOGDEST_H
27
#define QSLOGDEST_H
28

    
29
#include "QsLogLevel.h"
30
#include <QSharedPointer>
31
#include <QtGlobal>
32
class QString;
33
class QObject;
34

    
35
#ifdef QSLOG_IS_SHARED_LIBRARY
36
#define QSLOG_SHARED_OBJECT Q_DECL_EXPORT
37
#elif QSLOG_IS_SHARED_LIBRARY_IMPORT
38
#define QSLOG_SHARED_OBJECT Q_DECL_IMPORT
39
#else
40
#define QSLOG_SHARED_OBJECT
41
#endif
42

    
43
namespace QsLogging
44
{
45

    
46
class QSLOG_SHARED_OBJECT Destination
47
{
48
public:
49
    typedef void (*LogFunction)(const QString &message, Level level);
50

    
51
public:
52
    virtual ~Destination();
53
    virtual void write(const QString& message, Level level) = 0;
54
    virtual bool isValid() = 0; // returns whether the destination was created correctly
55
};
56
typedef QSharedPointer<Destination> DestinationPtr;
57

    
58

    
59
// a series of "named" paramaters, to make the file destination creation more readable
60
enum LogRotationOption
61
{
62
    DisableLogRotation = 0,
63
    EnableLogRotation  = 1
64
};
65

    
66
struct QSLOG_SHARED_OBJECT MaxSizeBytes
67
{
68
    MaxSizeBytes() : size(0) {}
69
    explicit MaxSizeBytes(qint64 size_) : size(size_) {}
70
    qint64 size;
71
};
72

    
73
struct QSLOG_SHARED_OBJECT MaxOldLogCount
74
{
75
    MaxOldLogCount() : count(0) {}
76
    explicit MaxOldLogCount(int count_) : count(count_) {}
77
    int count;
78
};
79

    
80

    
81
//! Creates logging destinations/sinks. The caller shares ownership of the destinations with the logger.
82
//! After being added to a logger, the caller can discard the pointers.
83
class QSLOG_SHARED_OBJECT DestinationFactory
84
{
85
public:
86
    static DestinationPtr MakeFileDestination(const QString& filePath,
87
        LogRotationOption rotation = DisableLogRotation,
88
        const MaxSizeBytes &sizeInBytesToRotateAfter = MaxSizeBytes(),
89
        const MaxOldLogCount &oldLogsToKeep = MaxOldLogCount());
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
98

    
99
#endif // QSLOGDEST_H
(8-8/19)