summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/logger/AbstractAppender.h
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/logger/AbstractAppender.h')
-rw-r--r--rbutil/rbutilqt/logger/AbstractAppender.h125
1 files changed, 125 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/logger/AbstractAppender.h b/rbutil/rbutilqt/logger/AbstractAppender.h
new file mode 100644
index 0000000000..df1df4957c
--- /dev/null
+++ b/rbutil/rbutilqt/logger/AbstractAppender.h
@@ -0,0 +1,125 @@
1/*
2 Copyright (c) 2010 Boris Moiseev (cyberbobs at gmail dot com)
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License version 2.1
6 as published by the Free Software Foundation and appearing in the file
7 LICENSE.LGPL included in the packaging of this file.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13*/
14#ifndef ABSTRACTAPPENDER_H
15#define ABSTRACTAPPENDER_H
16
17// Local
18#include "CuteLogger_global.h"
19#include <Logger.h>
20
21// Qt
22#include <QMutex>
23
24//! The AbstractAppender class provides an abstract base class for writing a log entries.
25/**
26 * The AbstractAppender class is the base interface class for all log appenders that could be used with Logger.
27 *
28 * AbstractAppender provides a common implementation for the thread safe, mutex-protected logging of application
29 * messages, such as ConsoleAppender, FileAppender or something else. AbstractAppender is abstract and can not be
30 * instantiated, but you can use any of its subclasses or create a custom log appender at your choice.
31 *
32 * Appenders are the logical devices that is aimed to be attached to Logger object by calling
33 * Logger::registerAppender(). On each log record call from the application Logger object sequentially calls write()
34 * function on all the appenders registered in it.
35 *
36 * You can subclass AbstractAppender to implement a logging target of any kind you like. It may be the external logging
37 * subsystem (for example, syslog in *nix), XML file, SQL database entries, D-Bus messages or anything else you can
38 * imagine.
39 *
40 * For the simple non-structured plain text logging (for example, to a plain text file or to the console output) you may
41 * like to subclass the AbstractStringAppender instead of AbstractAppender, which will give you a more convinient way to
42 * control the format of the log output.
43 *
44 * \sa AbstractStringAppender
45 * \sa Logger::registerAppender()
46 */
47class CUTELOGGERSHARED_EXPORT AbstractAppender
48{
49 public:
50 //! Constructs a AbstractAppender object.
51 AbstractAppender();
52
53 //! Destructs the AbstractAppender object.
54 virtual ~AbstractAppender();
55
56 //! Returns the current details level of appender.
57 /**
58 * Log records with a log level lower than a current detailsLevel() will be silently ignored by appender and would not
59 * be sent to its append() function.
60 *
61 * It provides additional logging flexibility, allowing you to set the different severity levels for different types
62 * of logs.
63 *
64 * \note This function is thread safe.
65 *
66 * \sa setDetailsLevel()
67 * \sa Logger::LogLevel
68 */
69 Logger::LogLevel detailsLevel() const;
70
71 //! Sets the current details level of appender.
72 /**
73 * \note This function is thread safe.
74 *
75 * \sa detalsLevel()
76 * \sa Logger::LogLevel
77 */
78 void setDetailsLevel(Logger::LogLevel level);
79
80 //! Sets the current details level of appender
81 /**
82 * This function is provided for convinience, it behaves like an above function.
83 *
84 * \sa detalsLevel()
85 * \sa Logger::LogLevel
86 */
87 void setDetailsLevel(const QString& level);
88
89 //! Tries to write the log record to this logger
90 /**
91 * This is the function called by Logger object to write a log message to the appender.
92 *
93 * \note This function is thread safe.
94 *
95 * \sa Logger::write()
96 * \sa detailsLevel()
97 */
98 void write(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line, const char* function,
99 const QString& message);
100
101 protected:
102 //! Writes the log record to the logger instance
103 /**
104 * This function is called every time when user tries to write a message to this AbstractAppender instance using
105 * the write() function. Write function works as proxy and transfers only the messages with log level more or equal
106 * to the current logLevel().
107 *
108 * Overload this function when you are implementing a custom appender.
109 *
110 * \note This function is not needed to be thread safe because it is never called directly by Logger object. The
111 * write() function works as a proxy and protects this function from concurrent access.
112 *
113 * \sa Logger::write()
114 */
115 virtual void append(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line,
116 const char* function, const QString& message) = 0;
117
118 private:
119 QMutex m_writeMutex;
120
121 Logger::LogLevel m_detailsLevel;
122 mutable QMutex m_detailsLevelMutex;
123};
124
125#endif // ABSTRACTAPPENDER_H