diff --git a/.gitignore b/.gitignore index 46167d9b1aeb3b382a60929592d05ffee1b93c41..65d1c0f58dea42e8ca7df55711751fc95f486f92 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ bin/rms *~ *.swp build/* -compile/* .qmake.stash moc_* Makefile diff --git a/Include/t b/Include/t deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/README.md b/README.md index 28e6ee984d3f719d0b324199a7467409a4382dc5..80c819515864117c47667e9704aaf19c84761448 100644 --- a/README.md +++ b/README.md @@ -1,77 +1,4 @@ -# FoodBevManage -这个是餐饮管理系统 +# RMS -本程序跨平台,支持linux和win完美运行 - -添加程序目录结构 - -```html -├── copyleft -├── data.db -├── dist -├── doc -├── FoodBevManage.pro -├── FoodBevManage.pro.user -├── lib -├── README.md -├── res -│   ├── images -│   │   ├── Add.png -│   │   ├── addUser.png -│   │   ├── Login.png -│   │   ├── Quit.png -│   │   ├── Reckoning.png -│   │   ├── Start.png -│   │   └── Stat.png -│   └── ui -│   ├── add_reduce_dialog.ui -│   ├── check_outdialog.ui -│   ├── dayincomequery_dialog.ui -│   ├── dishescountdialog.ui -│   ├── foodinfo_dialog.ui -│   ├── logindialog.ui -│   ├── mainwindow.ui -│   ├── monthincomequery_dialog.ui -│   ├── orderdishesdialog.ui -│   ├── selectseatdialog.ui -│   ├── staffregister_dialog.ui -│   ├── stockquery_dialog.ui -│   └── varietymenudialog.ui -├── res.qrc -├── samples -├── src -│   ├── include -│   │   ├── add_reduce_dialog.h -│   │   ├── check_outdialog.h -│   │   ├── dayincomequery_dialog.h -│   │   ├── daystatistics.h -│   │   ├── dishescountdialog.h -│   │   ├── foodinfo_dialog.h -│   │   ├── logindialog.h -│   │   ├── mainwindow.h -│   │   ├── monthincomequery_dialog.h -│   │   ├── orderdishesdialog.h -│   │   ├── selectseatdialog.h -│   │   ├── staffregister_dialog.h -│   │   ├── stockqquery_dialog.h -│   │   └── varietymenudialog.h -│   └── source -│   ├── add_reduce_dialog.cpp -│   ├── check_outdialog.cpp -│   ├── dayincomequery_dialog.cpp -│   ├── daystatistics.cpp -│   ├── dishescountdialog.cpp -│   ├── foodinfo_dialog.cpp -│   ├── logindialog.cpp -│   ├── main.cpp -│   ├── mainwindow.cpp -│   ├── monthincomequery_dialog.cpp -│   ├── orderdishesdialog.cpp -│   ├── selectseatdialog.cpp -│   ├── staffregister_dialog.cpp -│   ├── stockqquery_dialog.cpp -│   └── varietymenudialog.cpp -└── tools - -``` +RMS是 RestaurantManagementSystem(餐厅管理系统)缩写 diff --git a/bin/startup.sh b/bin/startup.sh index 5ae6c77233d2ce10645b5e2fa488024e3da71e0e..494fde8272dcb1033bb9b43e35909474fa4c8fdd 100755 --- a/bin/startup.sh +++ b/bin/startup.sh @@ -20,7 +20,7 @@ BIN_DIR=${BASE_DIR}/bin LIB_DIR=${BASE_DIR}/lib # 配置sqlite3驱动环境变量 -export LD_LIBRARY_PATH=${LIB_DIR}/sqlite3:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=${LIB_DIR}/sqlite3:${LIB_DIR}/log4qt:$LD_LIBRARY_PATH # 启动程序 ${BIN_DIR}/${APP_NAME} diff --git a/config.pri b/config.pri deleted file mode 100644 index bf36b6b1f0618b2c2d31d9c99e1bab90456e1d30..0000000000000000000000000000000000000000 --- a/config.pri +++ /dev/null @@ -1,4 +0,0 @@ - -PROJECT_ROOT = $$PWD -BUILD_DIST = $$PROJECT_ROOT/bin -APP_TARGET = rms diff --git a/include/log4qt/appender.h b/include/log4qt/appender.h new file mode 100644 index 0000000000000000000000000000000000000000..f63d02daa6a23f9ff7aa3951a52f3c3e436ba5cf --- /dev/null +++ b/include/log4qt/appender.h @@ -0,0 +1,103 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_APPENDER_H +#define LOG4QT_APPENDER_H + +#include "layout.h" +#include "log4qtsharedptr.h" +#include "spi/filter.h" +#include "helpers/classlogger.h" + +namespace Log4Qt +{ + +class LoggingEvent; + +/*! + * \brief The class Appender is the base class for all Appenders. + * + * To allow the whole hirarchy to be an ascendant of QObject Appender is + * not an interface. + * + * \note All the functions declared in this class are thread-safe. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT Appender : public QObject +{ + Q_OBJECT + + /*! + * The property holds the Layout used by the Appender. + * + * \sa layout(), setLayout() + */ + Q_PROPERTY(LayoutSharedPtr layout READ layout WRITE setLayout) + + /*! + * The property holds the name of the Appender. + * + * \sa name(), setName() + */ + Q_PROPERTY(QString name READ name WRITE setName) + + /*! + * The property holds if the Appender requires a Layout or not. + * + * \sa requiresLayout(), setRequiresLayout() + */ + Q_PROPERTY(bool requiresLayout READ requiresLayout) + +public: + Appender(QObject *parent = nullptr); + virtual ~Appender(); + + virtual FilterSharedPtr filter() const = 0; + virtual QString name() const = 0; + virtual LayoutSharedPtr layout() const = 0; + virtual bool requiresLayout() const = 0; + virtual void setLayout(const LayoutSharedPtr &layout) = 0; + virtual void setName(const QString &name) = 0; + + virtual void addFilter(const FilterSharedPtr &filter) = 0; + virtual void clearFilters() = 0; + virtual void close() = 0; + virtual void doAppend(const LoggingEvent &event) = 0; + +protected: + /*! + * Returns a pointer to a Logger named after of the object. + * + * \sa Logger::logger() + */ + Logger *logger() const; + +private: + Q_DISABLE_COPY(Appender) + mutable ClassLogger mLog4QtClassLogger; +}; + +using AppenderSharedPtr = Log4QtSharedPtr; + +} // namespace Log4Qt + +#endif // LOG4QT_APPENDER_H diff --git a/include/log4qt/appenderskeleton.h b/include/log4qt/appenderskeleton.h new file mode 100644 index 0000000000000000000000000000000000000000..cf7008cadf3337b85cca0a83d10914ea36191966 --- /dev/null +++ b/include/log4qt/appenderskeleton.h @@ -0,0 +1,207 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_APPENDERSKELETON_H +#define LOG4QT_APPENDERSKELETON_H + +#include "appender.h" +#include "log4qtshared.h" +#include "layout.h" +#include "spi/filter.h" +#include "logger.h" + +#include + +namespace Log4Qt +{ + +class Logger; +class LoggingEvent; + +/*! + * \brief The class AppenderSkeleton implements general Appender functionality. + * + * \note All the functions declared in this class are thread-safe. + * + * \note The ownership and lifetime of objects of this class are managed. See + * \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT AppenderSkeleton : public Appender +{ + Q_OBJECT + + /*! + * The property holds if the Appender has been activated. + * + * \sa isActive() + */ + Q_PROPERTY(bool isActive READ isActive) + + /*! + * The property holds if the Appender has been closed. + * + * \sa isClosed() + */ + Q_PROPERTY(bool isClosed READ isClosed) + + /*! + * The property holds the threshold level used by the Appender. + * + * \sa threshold(), setThreshold() + */ + Q_PROPERTY(Log4Qt::Level threshold READ threshold WRITE setThreshold) + +public: + explicit AppenderSkeleton(QObject *parent = nullptr); + +protected: + explicit AppenderSkeleton(bool isActive, + QObject *parent = nullptr); + explicit AppenderSkeleton(bool isActive, + const LayoutSharedPtr &layout, + QObject *parent = nullptr); + ~AppenderSkeleton() override; + +public: + FilterSharedPtr filter() const override; + LayoutSharedPtr layout() const override; + bool isActive() const; + bool isClosed() const; + QString name() const override; + Level threshold() const; + void setLayout(const LayoutSharedPtr &layout) override; + void setName(const QString &name) override; + void setThreshold(Level level); + + virtual void activateOptions(); + void addFilter(const FilterSharedPtr &filter) override; + void clearFilters() override; + void close() override; + + /*! + * Performs checks and delegates the actuall appending to the subclass + * specific append() function. + * + * \sa append(), checkEntryConditions(), isAsSevereAsThreshold(), Filter + */ + void doAppend(const LoggingEvent &event) override; + + FilterSharedPtr firstFilter() const; + bool isAsSevereAsThreshold(Level level) const; + +protected: + virtual void append(const LoggingEvent &event) = 0; + void customEvent(QEvent *event) override; + + /*! + * Tests if all entry conditions for using append() in this class are + * met. + * + * If a conditions is not met, an error is logged and the function + * returns false. + * + * The checked conditions are: + * - That the appender has been activated (APPENDER_NOT_ACTIVATED_ERROR) + * - That the appender was not closed (APPENDER_CLOSED_ERROR) + * - That the appender has a layout set, if it requires one + * (logging_error(APPENDER_USE_MISSING_LAYOUT_ERROR) + * + * The function is called as part of the checkEntryConditions() chain + * started by doAppend(). The doAppend() function calls the subclass + * specific checkEntryConditions() function. The function checks the + * class specific conditions and calls checkEntryConditions() of + * it's parent class. The last function called is + * AppenderSkeleton::checkEntryConditions(). + * + * \sa doAppend() + */ + virtual bool checkEntryConditions() const; + +protected: +#if QT_VERSION < 0x050E00 + mutable QMutex mObjectGuard; +#else + mutable QRecursiveMutex mObjectGuard; +#endif + +private: + Q_DISABLE_COPY(AppenderSkeleton) + bool mAppendRecursionGuard; + volatile bool mIsActive; + volatile bool mIsClosed; + LayoutSharedPtr mpLayout; + Level mThreshold; + FilterSharedPtr mpHeadFilter; + FilterSharedPtr mpTailFilter; + void closeInternal(); +}; + +inline FilterSharedPtr AppenderSkeleton::filter() const +{ + QMutexLocker locker(&mObjectGuard); + return mpHeadFilter; +} + +inline QString AppenderSkeleton::name() const +{ + QMutexLocker locker(&mObjectGuard); + return objectName(); +} + +inline Level AppenderSkeleton::threshold() const +{ + return mThreshold; +} + +inline void AppenderSkeleton::setName(const QString &name) +{ + QMutexLocker locker(&mObjectGuard); + setObjectName(name); +} + +inline void AppenderSkeleton::setThreshold(Level level) +{ + mThreshold = level; +} + +inline bool AppenderSkeleton::isActive() const +{ + return mIsActive; +} + +inline bool AppenderSkeleton::isClosed() const +{ + return mIsClosed; +} + +inline FilterSharedPtr AppenderSkeleton::firstFilter() const +{ + QMutexLocker locker(&mObjectGuard); + return filter(); +} + +inline bool AppenderSkeleton::isAsSevereAsThreshold(Level level) const +{ + return (mThreshold <= level); +} + +} // namespace Log4Qt + +#endif // LOG4QT_APPENDERSKELETON_H diff --git a/include/log4qt/asyncappender.h b/include/log4qt/asyncappender.h new file mode 100644 index 0000000000000000000000000000000000000000..c98efb2217e03e62b29527126760c825fea27fa4 --- /dev/null +++ b/include/log4qt/asyncappender.h @@ -0,0 +1,93 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_ASYNCAPPENDER_H +#define LOG4QT_ASYNCAPPENDER_H + +#include "appenderskeleton.h" +#include "helpers/appenderattachable.h" + +namespace Log4Qt +{ + +class Dispatcher; + +/*! + * \brief The class AsyncAppender lets users log events asynchronously. + * + * The AsyncAppender will collect the events sent to it and then dispatch them to all the + * appenders that are attached to it. You can attach multiple appenders to an AsyncAppender. + * + * The AsyncAppender uses a separate thread to serve the events fromthe event loop. + * + * \note All the functions declared in this class are thread-safe. + *   + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT AsyncAppender : public AppenderSkeleton, public AppenderAttachable +{ + Q_OBJECT + +public: + AsyncAppender(QObject *parent = nullptr); + ~AsyncAppender() override; + + bool requiresLayout() const override; + + void activateOptions() override; + void close() override; + void callAppenders(const LoggingEvent &event) const; + + /*! + * Tests if all entry conditions for using append() in this class are + * met. + * + * If a conditions is not met, an error is logged and the function + * returns false. Otherwise the result of + * AppenderSkeleton::checkEntryConditions() is returned. + * + * The checked conditions are: + * - dispatcher thread running (APPENDER_ASNC_DISPATCHER_NOT_RUNNING) + * + * The function is called as part of the checkEntryConditions() chain + * started by AppenderSkeleton::doAppend(). + * + * \sa AppenderSkeleton::doAppend(), + * AppenderSkeleton::checkEntryConditions() + */ + bool checkEntryConditions() const override; + +protected: + void append(const LoggingEvent &event) override; + +private: + Q_DISABLE_COPY(AsyncAppender) + + //! Event dispatcher trhead + QThread *mThread; + Dispatcher *mDispatcher; + void closeInternal(); +}; + + +} // namespace Log4Qt + +#endif // LOG4QT_AsyncAppender_H diff --git a/include/log4qt/basicconfigurator.h b/include/log4qt/basicconfigurator.h new file mode 100644 index 0000000000000000000000000000000000000000..662e63880e926eb8e5ee778b58def37a72be0d9e --- /dev/null +++ b/include/log4qt/basicconfigurator.h @@ -0,0 +1,51 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_BASICCONFIGURATOR_H +#define LOG4QT_BASICCONFIGURATOR_H + +#include "log4qt.h" + +namespace Log4Qt +{ + +class Appender; + +/*! + * \brief The class BasicConfigurator provides a simple package + * configuration. + * + * \note All the functions declared in this class are thread-safe. + */ +class LOG4QT_EXPORT BasicConfigurator +{ +private: + Q_DISABLE_COPY(BasicConfigurator) + +public: + static bool configure(); + static void configure(Appender *pAppender); + static void resetConfiguration(); +}; + + +} // namspace + +#endif // _BASICCONFIGURATOR_H diff --git a/include/log4qt/binaryfileappender.h b/include/log4qt/binaryfileappender.h new file mode 100644 index 0000000000000000000000000000000000000000..7a6776a9f34665a6bc777100fcfae8d304ce35bb --- /dev/null +++ b/include/log4qt/binaryfileappender.h @@ -0,0 +1,163 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_BINARYFILEAPPENDER_H +#define LOG4QT_BINARYFILEAPPENDER_H + +#include "binarywriterappender.h" + +#include + +class QFile; + +namespace Log4Qt +{ + +class LOG4QT_EXPORT BinaryFileAppender : public BinaryWriterAppender +{ + Q_OBJECT + Q_PROPERTY(bool appendFile READ appendFile WRITE setAppendFile) + Q_PROPERTY(bool bufferedIo READ bufferedIo WRITE setBufferedIo) + Q_PROPERTY(QString file READ file WRITE setFile) + Q_PROPERTY(QDataStream::ByteOrder byteOrder READ byteOrder WRITE setByteOrder) + Q_PROPERTY(QDataStream::FloatingPointPrecision floatingPointPrecision READ floatingPointPrecision WRITE setFloatingPointPrecision) + Q_PROPERTY(QDataStream::Version streamVersion READ streamVersion WRITE setStreamVersion) + +public: + explicit BinaryFileAppender(QObject *parent = nullptr); + BinaryFileAppender(const QString &fileName, + QObject *parent = nullptr); + BinaryFileAppender(const QString &fileName, + bool append, + QObject *parent = nullptr); + BinaryFileAppender(const QString &fileName, + bool append, + bool buffered, + QObject *parent = nullptr); + virtual ~BinaryFileAppender(); + + // properties + bool appendFile() const; + void setAppendFile(bool append); + bool bufferedIo() const; + void setBufferedIo(bool buffered); + QString file() const; + void setFile(const QString &fileName); + QDataStream::ByteOrder byteOrder() const; + void setByteOrder(QDataStream::ByteOrder byteorder); + QDataStream::FloatingPointPrecision floatingPointPrecision() const; + void setFloatingPointPrecision(QDataStream::FloatingPointPrecision floatingpointprecision); + QDataStream::Version streamVersion() const; + void setStreamVersion(QDataStream::Version version); + + // public members + void activateOptions() override; + void close() override; + +protected: + bool checkEntryConditions() const override; + bool handleIoErrors() const override; + + void closeFile(); + void openFile(); + bool removeFile(QFile &file) const; + bool renameFile(QFile &file, const QString &fileName) const; + +private: + BinaryFileAppender(const BinaryFileAppender &other); // Not implemented + BinaryFileAppender &operator=(const BinaryFileAppender &other); // Not implemented + void createDataStream(); + + volatile bool mAppendFile; + volatile bool mBufferedIo; + QString mFileName; + QFile *mFile; + QDataStream *mDataStream; + QDataStream::ByteOrder mByteOrder; + QDataStream::FloatingPointPrecision mFloatingPointPrecision; + QDataStream::Version mStreamVersion; + void closeInternal(); +}; + +inline bool BinaryFileAppender::appendFile() const +{ + return mAppendFile; +} + +inline QString BinaryFileAppender::file() const +{ + QMutexLocker locker(&mObjectGuard); + return mFileName; +} + +inline bool BinaryFileAppender::bufferedIo() const +{ + return mBufferedIo; +} + +inline void BinaryFileAppender::setAppendFile(bool append) +{ + mAppendFile = append; +} + +inline void BinaryFileAppender::setBufferedIo(bool buffered) +{ + mBufferedIo = buffered; +} + +inline void BinaryFileAppender::setFile(const QString &fileName) +{ + QMutexLocker locker(&mObjectGuard); + mFileName = fileName; +} + +inline QDataStream::ByteOrder BinaryFileAppender::byteOrder() const +{ + return mByteOrder; +} + +inline void BinaryFileAppender::setByteOrder(QDataStream::ByteOrder byteorder) +{ + mByteOrder = byteorder; +} + +inline QDataStream::FloatingPointPrecision BinaryFileAppender::floatingPointPrecision() const +{ + return mFloatingPointPrecision; +} + +inline void BinaryFileAppender::setFloatingPointPrecision(QDataStream::FloatingPointPrecision floatingpointprecision) +{ + mFloatingPointPrecision = floatingpointprecision; +} + +inline QDataStream::Version BinaryFileAppender::streamVersion() const +{ + return mStreamVersion; +} + +inline void BinaryFileAppender::setStreamVersion(QDataStream::Version version) +{ + mStreamVersion = version; +} + +} // namespace Log4Qt + +#endif // LOG4QT_BINARYFILEAPPENDER_H diff --git a/include/log4qt/binarylayout.h b/include/log4qt/binarylayout.h new file mode 100644 index 0000000000000000000000000000000000000000..8907ae8f22f575cbc6a4a161e8cf256dea92ce31 --- /dev/null +++ b/include/log4qt/binarylayout.h @@ -0,0 +1,83 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_BINARYLAYOUT_H +#define LOG4QT_BINARYLAYOUT_H + +#include "layout.h" + +#include + +namespace Log4Qt +{ + +class LoggingEvent; +class BinaryLoggingEvent; + +class LOG4QT_EXPORT BinaryLayout : public Layout +{ + Q_OBJECT + Q_PROPERTY(QByteArray binaryFooter READ binaryFooter WRITE setBinaryFooter) + Q_PROPERTY(QByteArray binaryHeader READ binaryHeader WRITE setBinaryHeader) + +public: + explicit BinaryLayout(QObject *parent = nullptr); + + virtual QByteArray binaryFormat(const BinaryLoggingEvent &event) const; + virtual QString format(const LoggingEvent &event) override; + + virtual QString contentType() const override; + + virtual QByteArray binaryFooter() const; + void setBinaryFooter(const QByteArray &footer); + + virtual QByteArray binaryHeader() const; + void setBinaryHeader(const QByteArray &header); + +private: + Q_DISABLE_COPY(BinaryLayout) + + QByteArray mFooter; + QByteArray mHeader; +}; + +inline QByteArray BinaryLayout::binaryFooter() const +{ + return mFooter; +} + +inline void BinaryLayout::setBinaryFooter(const QByteArray &footer) +{ + mFooter = footer; +} + +inline QByteArray BinaryLayout::binaryHeader() const +{ + return mHeader; +} + +inline void BinaryLayout::setBinaryHeader(const QByteArray &header) +{ + mHeader = header; +} + +} // namespace Log4Qt + +#endif // LOG4QT_BINARYLAYOUT_H diff --git a/include/log4qt/binarylogger.h b/include/log4qt/binarylogger.h new file mode 100644 index 0000000000000000000000000000000000000000..57b070715cde45c19ffd31a6e4bbde61023fc05c --- /dev/null +++ b/include/log4qt/binarylogger.h @@ -0,0 +1,91 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_BINARYLOGGER_H +#define LOG4QT_BINARYLOGGER_H + +#include "logger.h" +#include "binarylogstream.h" +#include "helpers/binaryclasslogger.h" + +class QByteArray; + +namespace Log4Qt +{ + +class Appender; +class BinaryLoggingEvent; +class LoggerRepository; +class Hierarchy; + +#define LOG4QT_DECLARE_STATIC_BINARYLOGGER(FUNCTION, CLASS) \ + static Log4Qt::BinaryLogger *FUNCTION() \ + { \ + static Log4Qt::Logger * p_logger(Log4Qt::Logger::logger(#CLASS"@@binary@@" )); \ + return qobject_cast(p_logger); \ + } + +#define LOG4QT_DECLARE_QCLASS_BINARYLOGGER \ + private: \ + mutable Log4Qt::BinaryClassLogger mLog4QtClassLogger; \ + public: \ + inline Log4Qt::BinaryLogger *logger() const \ + { \ + return mLog4QtClassLogger.logger(this); \ + } \ + private: + +class LOG4QT_EXPORT BinaryLogger : public Logger +{ + Q_OBJECT +public: + BinaryLogStream debug() const {return log(Level::DEBUG_INT);} + void debug(const QByteArray &message) const {log(Level::DEBUG_INT, message);} + BinaryLogStream error() const {return log(Level::ERROR_INT);} + void error(const QByteArray &message) const {log(Level::ERROR_INT, message);} + BinaryLogStream fatal() const {return log(Level::FATAL_INT);} + void fatal(const QByteArray &message) const {log(Level::FATAL_INT, message);} + BinaryLogStream info() const {return log(Level::INFO_INT);} + void info(const QByteArray &message) const {log(Level::INFO_INT, message);} + BinaryLogStream trace() const {return log(Level::TRACE_INT);} + void trace(const QByteArray &message) const {log(Level::TRACE_INT, message);} + BinaryLogStream warn() const {return log(Level::WARN_INT);} + void warn(const QByteArray &message) const {log(Level::WARN_INT, message);} + + BinaryLogStream log(Level level) const; + void log(Level level, const QByteArray &message) const; + void log(Level level, const QByteArray &message, QDateTime timeStamp) const; + +protected: + BinaryLogger(LoggerRepository *loggerRepository, Level level, const QString &name, Logger *parent = nullptr); + virtual ~BinaryLogger(); + + void forcedLog(Level level, const QByteArray &message) const; + +private: + BinaryLogger(const BinaryLogger &other); // Not implemented + BinaryLogger &operator=(const BinaryLogger &other); // Not implemented + // Needs to be friend to create BinaryLogger objects + friend class Hierarchy; +}; + +} // namespace Log4Qt + +#endif // LOG4QT_BINARYLOGGER_H diff --git a/include/log4qt/binaryloggingevent.h b/include/log4qt/binaryloggingevent.h new file mode 100644 index 0000000000000000000000000000000000000000..767e966fe091afd2b8c359f3f6434426c3ac14c1 --- /dev/null +++ b/include/log4qt/binaryloggingevent.h @@ -0,0 +1,73 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_BINARYLOGGINGEVENT_H +#define LOG4QT_BINARYLOGGINGEVENT_H + +#include "loggingevent.h" + +namespace Log4Qt +{ + +class LOG4QT_EXPORT BinaryLoggingEvent : public LoggingEvent +{ +public: + BinaryLoggingEvent(); + BinaryLoggingEvent(const Logger *logger, + Level level, + const QByteArray &message); + BinaryLoggingEvent(const Logger *logger, + Level level, + const QByteArray &message, + qint64 timeStamp); + BinaryLoggingEvent(const Logger *logger, + Level level, + const QByteArray &message, + const QString &ndc, + const QHash &properties, + const QString &threadName, + qint64 timeStamp); + QByteArray binaryMessage() const; + + QString toString() const; + + static QString binaryMarker(); + +private: + QByteArray mBinaryMessage; + +#ifndef QT_NO_DATASTREAM + // Needs to be friend to stream objects + friend LOG4QT_EXPORT QDataStream &operator<<(QDataStream &out, const BinaryLoggingEvent &loggingEvent); + friend LOG4QT_EXPORT QDataStream &operator>>(QDataStream &in, BinaryLoggingEvent &loggingEvent); +#endif // QT_NO_DATASTREAM +}; + +#ifndef QT_NO_DATASTREAM +LOG4QT_EXPORT QDataStream &operator<<(QDataStream &out, const BinaryLoggingEvent &loggingEvent); +LOG4QT_EXPORT QDataStream &operator>>(QDataStream &in, BinaryLoggingEvent &loggingEvent); +#endif // QT_NO_DATASTREAM + +} // namespace Log4Qt + +Q_DECLARE_METATYPE(Log4Qt::BinaryLoggingEvent) +Q_DECLARE_TYPEINFO(Log4Qt::BinaryLoggingEvent, Q_MOVABLE_TYPE); + +#endif // LOG4QT_BINARYLOGGINGEVENT_H diff --git a/include/log4qt/binarylogstream.h b/include/log4qt/binarylogstream.h new file mode 100644 index 0000000000000000000000000000000000000000..f18bc6deefff850ff8919edbd50f4ee1105e45a1 --- /dev/null +++ b/include/log4qt/binarylogstream.h @@ -0,0 +1,48 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_BINARYLOGSTREAM_H +#define LOG4QT_BINARYLOGSTREAM_H + +#include + +#include "level.h" + +class QByteArray; + +namespace Log4Qt +{ +class Logger; + +class LOG4QT_EXPORT BinaryLogStream +{ +public: + BinaryLogStream(const Logger *logger, Level level); + + BinaryLogStream &operator<<(const QByteArray &data); + +private: + struct Stream; + QSharedPointer mStream; +}; + +} // namespace Log4Qt + +#endif // LOG4QT_BINARYLOGSTREAM_H diff --git a/include/log4qt/binarytotextlayout.h b/include/log4qt/binarytotextlayout.h new file mode 100644 index 0000000000000000000000000000000000000000..6055759796b7babd101f2e05597c45c7a26d5ba6 --- /dev/null +++ b/include/log4qt/binarytotextlayout.h @@ -0,0 +1,49 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_BINARYTOTEXTLAYOUT_H +#define LOG4QT_BINARYTOTEXTLAYOUT_H + +#include "layout.h" + +namespace Log4Qt +{ + +//! Used to format binary messages for a textual appenders +class LOG4QT_EXPORT BinaryToTextLayout : public Layout +{ + Q_OBJECT + Q_PROPERTY(LayoutSharedPtr subLayout READ subLayout WRITE setSubLayout) +public: + explicit BinaryToTextLayout(const LayoutSharedPtr &subLayout = LayoutSharedPtr(), QObject *parent = nullptr); + + virtual QString format(const LoggingEvent &event) override; + + LayoutSharedPtr subLayout() const {return mSubLayout;} + void setSubLayout(const LayoutSharedPtr &layout) {mSubLayout = layout;} + +private: + Q_DISABLE_COPY(BinaryToTextLayout) + LayoutSharedPtr mSubLayout; +}; + +} // namespace Log4Qt + +#endif // LOG4QT_BINARYTOTEXTLAYOUT_H diff --git a/include/log4qt/binarywriterappender.h b/include/log4qt/binarywriterappender.h new file mode 100644 index 0000000000000000000000000000000000000000..13b55c6c005bc5df41628c9f5fa1b5505b8bd101 --- /dev/null +++ b/include/log4qt/binarywriterappender.h @@ -0,0 +1,75 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_BINARYWRITTERAPPENDER_H +#define LOG4QT_BINARYWRITTERAPPENDER_H + +#include "appenderskeleton.h" + +class QDataStream; +namespace Log4Qt +{ + +class BinaryLayout; + +class LOG4QT_EXPORT BinaryWriterAppender : public AppenderSkeleton +{ + Q_OBJECT + Q_PROPERTY(QDataStream *writer READ writer WRITE setWriter) +public: + BinaryWriterAppender(QObject *parent = nullptr); + BinaryWriterAppender(QDataStream *dataStream, QObject *parent = nullptr); + ~BinaryWriterAppender() override; + + bool requiresLayout() const override; + QDataStream *writer() const; + + void setWriter(QDataStream *dataStream); + + void activateOptions() override; + void close() override; + +protected: + void append(const LoggingEvent &event) override; + bool checkEntryConditions() const override; + + void closeWriter(); + + virtual bool handleIoErrors() const; + void writeFooter() const; + void writeHeader() const; + +private: + Q_DISABLE_COPY(BinaryWriterAppender) + void writeRawData(const QByteArray &data) const; + void closeInternal(); + BinaryLayout *binaryLayout() const; + + QDataStream *mWriter; +}; + +inline QDataStream *BinaryWriterAppender::writer() const +{ + return mWriter; +} + +} // namespace Log4Qt + +#endif // LOG4QT_BINARYWRITTERAPPENDER_H diff --git a/include/log4qt/consoleappender.h b/include/log4qt/consoleappender.h new file mode 100644 index 0000000000000000000000000000000000000000..6c768dfeeccf6a9f54a7f27b356357fc2b9f8a97 --- /dev/null +++ b/include/log4qt/consoleappender.h @@ -0,0 +1,116 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_CONSOLEAPPENDER_H +#define LOG4QT_CONSOLEAPPENDER_H + +#include "writerappender.h" + +class QTextStream; + +namespace Log4Qt +{ + +/*! + * \brief The class ConsoleAppender appends to stdout or stderr. + * + * \note All the functions declared in this class are thread-safe. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT ConsoleAppender : public WriterAppender +{ + Q_OBJECT + + /*! + * The property holds the target used by the appender. + * + * The default is STDOUT_TARGET for the standard output. + * + * \sa Target, target(), setTarget() + */ + Q_PROPERTY(QString target READ target WRITE setTarget) + +public: + /*! + * The enum defines the possible output targets + * + * \sa target(), setTarget() + */ + enum Target + { + /*! The output target is standard out. */ + STDOUT_TARGET, + /*! The output target is standard error. */ + STDERR_TARGET + }; + Q_ENUM(Target) + + + ConsoleAppender(QObject *parent = nullptr); + ConsoleAppender(const LayoutSharedPtr &pLayout, + QObject *parent = nullptr); + ConsoleAppender(const LayoutSharedPtr &pLayout, + const QString &target, + QObject *parent = nullptr); + + /*! + * Creates a ConsoleAppender with the layout \a pLayout, the target + * value specified by the \a target constant and the parent + * \a parent. + */ + ConsoleAppender(const LayoutSharedPtr &pLayout, + Target target, + QObject *parent = nullptr); + + ~ConsoleAppender() override; +private: + Q_DISABLE_COPY(ConsoleAppender) + +public: + QString target() const; + void setTarget(const QString &target); + + /*! + * Sets the target to the value specified by the \a target constant. + */ + void setTarget(Target target); + + virtual void activateOptions() override; + virtual void close() override; + +protected: + void closeStream(); + +private: + volatile Target mTarget; + QTextStream *mtextStream; + void closeInternal(); +}; + +inline void ConsoleAppender::setTarget(Target target) +{ + mTarget = target; +} + +} // namespace Log4Qt + +#endif // _CONSOLEAPPENDER_H diff --git a/include/log4qt/dailyfileappender.h b/include/log4qt/dailyfileappender.h new file mode 100644 index 0000000000000000000000000000000000000000..6925293ef8c70d06c9a48ceb12abf986d4188697 --- /dev/null +++ b/include/log4qt/dailyfileappender.h @@ -0,0 +1,104 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_DAILYFILEAPPENDER_H +#define LOG4QT_DAILYFILEAPPENDER_H + +#include "fileappender.h" + +#include +#include +#include +#include + +namespace Log4Qt +{ + +class LOG4QT_EXPORT IDateRetriever +{ +public: + virtual ~IDateRetriever(); + virtual QDate currentDate() const = 0; +}; + +class LOG4QT_EXPORT DefaultDateRetriever final : public IDateRetriever +{ +public: + + /** + * Return the current date, as reported by the system clock. + */ + QDate currentDate() const override; +}; + +/*! + * \brief The class DailyFileAppender extends FileAppender so that the + * a log file is created for each day + */ +class LOG4QT_EXPORT DailyFileAppender : public FileAppender +{ + Q_OBJECT + + //! The property holds the date pattern used by the appender. + Q_PROPERTY(QString datePattern READ datePattern WRITE setDatePattern) + + /** + * Number of days that old log files will be kept on disk. + * Set to a positive value to enable automatic deletion. Per default, all files are kept. Check + * for obsolete files happens once a day. + */ + Q_PROPERTY(int keepDays READ keepDays WRITE setKeepDays) + +public: + explicit DailyFileAppender(QObject *parent = nullptr); + DailyFileAppender(const LayoutSharedPtr &layout, const QString &fileName, const QString &datePattern = QString(), int keepDays = 0, QObject *parent = nullptr); + + QString datePattern() const; + void setDatePattern(const QString &datePattern); + + int keepDays() const; + void setKeepDays(int keepDays); + + void activateOptions() override; + + void append(const LoggingEvent &event) override; + + void setDateRetriever(const QSharedPointer &dateRetriever); + +private: + Q_DISABLE_COPY(DailyFileAppender) + + void setLogFileForCurrentDay(); + void rollOver(); + QString appendDateToFilename() const; + + QSharedPointer mDateRetriever; + + QString mDatePattern; + QDate mLastDate; + int mKeepDays; + QString mOriginalFilename; + + QFutureSynchronizer mDeleteObsoleteFilesExecutors; +}; + +} + +#endif // LOG4QT_DAILYFILEAPPENDER_H diff --git a/include/log4qt/dailyrollingfileappender.h b/include/log4qt/dailyrollingfileappender.h new file mode 100644 index 0000000000000000000000000000000000000000..d8aff275258603124ec39801b22669a9a7663adf --- /dev/null +++ b/include/log4qt/dailyrollingfileappender.h @@ -0,0 +1,148 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_DAILYROLLINGFILEAPPENDER_H +#define LOG4QT_DAILYROLLINGFILEAPPENDER_H + +#include "fileappender.h" + +#include + +namespace Log4Qt +{ + +/*! + * \brief The class DailyRollingFileAppender extends FileAppender so that the + * underlying file is rolled over at a specified frequency. + * + * \note All the functions declared in this class are thread-safe. + * + * \note The ownership and lifetime of objects of this class are managed. See + * \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT DailyRollingFileAppender : public FileAppender +{ + Q_OBJECT + + /*! + * The property holds the date pattern used by the appender. + * + * The default is DAILY_ROLLOVER for rollover at midnight each day. + * + * \sa datePattern(), setDatePattern() + */ + Q_PROPERTY(QString datePattern READ datePattern WRITE setDatePattern) + +public: + /*! + * The enum DatePattern defines constants for date patterns. + * + * \sa setDatePattern(DatePattern) + */ + enum DatePattern + { + /*! The minutely date pattern string is "'.'yyyy-MM-dd-hh-mm". */ + MINUTELY_ROLLOVER = 0, + /*! The hourly date pattern string is "'.'yyyy-MM-dd-hh". */ + HOURLY_ROLLOVER, + /*! The half-daily date pattern string is "'.'yyyy-MM-dd-a". */ + HALFDAILY_ROLLOVER, + /*! The daily date pattern string is "'.'yyyy-MM-dd". */ + DAILY_ROLLOVER, + /*! The weekly date pattern string is "'.'yyyy-ww". */ + WEEKLY_ROLLOVER, + /*! The monthly date pattern string is "'.'yyyy-MM". */ + MONTHLY_ROLLOVER + }; + Q_ENUM(DatePattern) + + DailyRollingFileAppender(QObject *parent = nullptr); + DailyRollingFileAppender(const LayoutSharedPtr &layout, + const QString &fileName, + const QString &datePattern, + QObject *parent = nullptr); + +private: + Q_DISABLE_COPY(DailyRollingFileAppender) +public: + QString datePattern() const; + + /*! + * Sets the datePattern to the value specified by the \a datePattern + * constant. + */ + void setDatePattern(DatePattern datePattern); + + void setDatePattern(const QString &datePattern); + + void activateOptions() override; + +protected: + void append(const LoggingEvent &event) override; + + /*! + * Tests if all entry conditions for using append() in this class are + * met. + * + * If a conditions is not met, an error is logged and the function + * returns false. Otherwise the result of + * FileAppender::checkEntryConditions() is returned. + * + * The checked conditions are: + * - A valid pattern has been set (APPENDER_USE_INVALID_PATTERN_ERROR) + * + * The function is called as part of the checkEntryConditions() chain + * started by AppenderSkeleton::doAppend(). + * + * \sa AppenderSkeleton::doAppend(), + * AppenderSkeleton::checkEntryConditions() + */ + bool checkEntryConditions() const override; + +private: + void computeFrequency(); + void computeRollOvetime(); + QString frequencyToString() const; + void rollOver(); + +private: + QString mDatePattern; + DatePattern mFrequency; + QString mActiveDatePattern; + QDateTime mRollOvetime; + QString mRollOverSuffix; +}; + +inline QString DailyRollingFileAppender::datePattern() const +{ + QMutexLocker locker(&mObjectGuard); + return mDatePattern; +} + +inline void DailyRollingFileAppender::setDatePattern(const QString &datePattern) +{ + QMutexLocker locker(&mObjectGuard); + mDatePattern = datePattern; +} + + +} // namespace Log4Qt + +#endif // LOG4QT_DAILYROLLINGFILEAPPENDER_H diff --git a/include/log4qt/fileappender.h b/include/log4qt/fileappender.h new file mode 100644 index 0000000000000000000000000000000000000000..0cd23e7ff409b0ad89911c6943b6ce9db9e9606d --- /dev/null +++ b/include/log4qt/fileappender.h @@ -0,0 +1,194 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_FILEAPPENDER_H +#define LOG4QT_FILEAPPENDER_H + +#include "writerappender.h" + +class QFile; +class QTextStream; + +namespace Log4Qt +{ + +/*! + * \brief The class FileAppender appends log events to a file. + * + * \note All the functions declared in this class are thread-safe. + * + * \note The ownership and lifetime of objects of this class are managed. See + * \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT FileAppender : public WriterAppender +{ + Q_OBJECT + + /*! + * The property holds, if the output is appended to the file. + * + * The default is false for not appending. + * + * \sa appendFile(), setAppendFile() + */ + Q_PROPERTY(bool appendFile READ appendFile WRITE setAppendFile) + + /*! + * The property holds, if the output is buffered. + * + * The default is true for buffering. + * + * \sa bufferedIo(), setBufferedIo() + */ + Q_PROPERTY(bool bufferedIo READ bufferedIo WRITE setBufferedIo) + + /*! + * The property holds the name of the file. + * + * \sa file(), setFile() + */ + Q_PROPERTY(QString file READ file WRITE setFile) + +public: + explicit FileAppender(QObject *parent = nullptr); + FileAppender(const LayoutSharedPtr &layout, + const QString &fileName, + QObject *parent = nullptr); + FileAppender(const LayoutSharedPtr &layout, + const QString &fileName, + bool append, + QObject *parent = nullptr); + FileAppender(const LayoutSharedPtr &layout, + const QString &fileName, + bool append, + bool buffered, + QObject *parent = nullptr); + ~FileAppender() override; + +private: + Q_DISABLE_COPY(FileAppender) + +public: + bool appendFile() const; + QString file() const; + bool bufferedIo() const; + void setAppendFile(bool append); + void setBufferedIo(bool buffered); + void setFile(const QString &fileName); + + void activateOptions() override; + void close() override; + +protected: + /*! + * Tests if all entry conditions for using append() in this class are met. + * + * If a conditions is not met, an error is logged and the function returns + * false. Otherwise the result of WriterAppender::checkEntryConditions() + * is returned. + * + * The checked conditions are: + * - That a file is set and open (APPENDER_NO_OPEN_FILE_ERROR) + * + * The function is called as part of the checkEntryConditions() chain + * started by AppenderSkeleton::doAppend(). + * + * \sa AppenderSkeleton::doAppend(), AppenderSkeleton::checkEntryConditions() + */ + bool checkEntryConditions() const override; + + void closeFile(); + + /*! + * Checks for file I/O errrors. If an error is found it is logged and the + * function returns true. Otherwise false is returned. + */ + bool handleIoErrors() const override; + + /*! + * Opens the file for the appender based on the specified file name and + * mode. A text stream is created and passed on to the super class + * WriterAppender. + * + * If the parent directory of the specified file does not exists, + * it is created. + */ + virtual void openFile(); + + /*! + * Removes the file \a file. If the operation is successful, true is + * returned. Otherwise an APPENDER_REMOVE_FILE_ERROR error is logged + * and false is returned. + */ + bool removeFile(QFile &file) const; + + /*! + * Renames the file \a file to \a fileName. If the operation is + * successful, true is returned. Otherwise an + * APPENDER_RENAMING_FILE_ERROR error is logged and false is returned. + */ + bool renameFile(QFile &file, + const QString &fileName) const; + +private: + volatile bool mAppendFile; + volatile bool mBufferedIo; + QString mFileName; + QFile *mFile; + QTextStream *mTextStream; + void closeInternal(); +}; + +inline bool FileAppender::appendFile() const +{ + return mAppendFile; +} + +inline QString FileAppender::file() const +{ + QMutexLocker locker(&mObjectGuard); + return mFileName; +} + +inline bool FileAppender::bufferedIo() const +{ + return mBufferedIo; +} + +inline void FileAppender::setAppendFile(bool append) +{ + mAppendFile = append; +} + +inline void FileAppender::setBufferedIo(bool buffered) +{ + mBufferedIo = buffered; +} + +inline void FileAppender::setFile(const QString &fileName) +{ + QMutexLocker locker(&mObjectGuard); + mFileName = fileName; +} + + +} // namespace Log4Qt + +#endif // LOG4QT_FILEAPPENDER_H diff --git a/include/log4qt/helpers/appenderattachable.h b/include/log4qt/helpers/appenderattachable.h new file mode 100644 index 0000000000000000000000000000000000000000..8b8c154f5a490381ac67e959d38c13c65ff995ba --- /dev/null +++ b/include/log4qt/helpers/appenderattachable.h @@ -0,0 +1,94 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_APPENDERATTACHABLE_H +#define LOG4QT_APPENDERATTACHABLE_H + +#include "log4qt/log4qt.h" +#include "log4qt/appender.h" + +#include +#include + +namespace Log4Qt +{ + +/*! + * \brief Implementation for attaching appenders to objects + */ +class LOG4QT_EXPORT AppenderAttachable +{ + +public: + AppenderAttachable(); + virtual ~AppenderAttachable(); + + /*! + * Add an appender. + */ + virtual void addAppender(const AppenderSharedPtr &appender); + + /*! + * Get all previously added appenders as an Enumeration. + */ + virtual QList appenders() const; + + /*! + * Get an appender by name. + */ + virtual AppenderSharedPtr appender(const QString &name) const; + + /*! + Returns true if the specified appender is in the + list of attached appenders, false otherwise. + */ + virtual bool isAttached(const AppenderSharedPtr &appender) const; + + /*! + * Removes all appenders that have been previously added from this + * Logger. + * + * To allow configurators to collect events during the configuration + * process ListAppenders with the configuratorList property set, will + * not be removed. + * + * \sa LisAppender::setConfiguratorList() + */ + virtual void removeAllAppenders(); + + /*! + * Remove the appender passed as parameter from the list of appenders. + */ + virtual void removeAppender(const AppenderSharedPtr &appender); + + /*! + * Remove the appender with the name passed as parameter from the + * list of appenders. + */ + virtual void removeAppender(const QString &name); + +protected: + QList mAppenders; + mutable QReadWriteLock mAppenderGuard; +}; + +} // namespace Log4Qt + +#endif // LOG4QT_APPENDERATTACHABLE_H diff --git a/include/log4qt/helpers/binaryclasslogger.h b/include/log4qt/helpers/binaryclasslogger.h new file mode 100644 index 0000000000000000000000000000000000000000..752475c2e5e410f1a5de704cec5dc6654c587e56 --- /dev/null +++ b/include/log4qt/helpers/binaryclasslogger.h @@ -0,0 +1,47 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_BINARYCLASSLOGGER_H +#define LOG4QT_BINARYCLASSLOGGER_H + +#include "log4qt/log4qtshared.h" + +#include + +class QObject; +namespace Log4Qt +{ + +class Logger; +class BinaryLogger; + +class LOG4QT_EXPORT BinaryClassLogger +{ +public: + BinaryClassLogger(); + BinaryLogger *logger(const QObject *object); + +private: + mutable QAtomicPointer mLogger; +}; + +} // namespace Log4Qt + +#endif // LOG4QT_BINARYCLASSLOGGER_H diff --git a/include/log4qt/helpers/classlogger.h b/include/log4qt/helpers/classlogger.h new file mode 100644 index 0000000000000000000000000000000000000000..d56276ec31c1d439470ac5640bcf0a018f8156c7 --- /dev/null +++ b/include/log4qt/helpers/classlogger.h @@ -0,0 +1,72 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_CLASSLOGGER_H +#define LOG4QT_CLASSLOGGER_H + +#include "log4qt/log4qtshared.h" + +#include + +class QObject; + +namespace Log4Qt +{ +class Logger; + +/*! + * \brief The class ClassLogger provides logging for a QObject derived + * class. + * + * The class ClassLogger provides a logger for a specified QObject derived + * object. It is used by \ref LOG4QT_DECLARE_QCLASS_LOGGER to implement the + * member functions provided by the macro. + * + * \note All the functions declared in this class are thread-safe. + * + * \sa LOG4QT_DECLARE_QCLASS_LOGGER + */ +class LOG4QT_EXPORT ClassLogger +{ +public: + /*! + * Creates a ClassLogger object. + */ + ClassLogger(); + + /*! + * Returns a pointer to a Logger named after the class of the object + * \a pObject. + * + * On the first invocation the Logger is requested by a call to + * LogManager::logger(const char *pName). The pointer is stored to be + * returned on subsequent invocations. + * + * \sa LogManager::logger(const char *pName) + */ + Logger *logger(const QObject *object); + +private: + mutable QAtomicPointer mLogger; +}; + +} // namespace Log4Qt + +#endif // LOG4QT_CLASSLOGGER_H diff --git a/include/log4qt/helpers/configuratorhelper.h b/include/log4qt/helpers/configuratorhelper.h new file mode 100644 index 0000000000000000000000000000000000000000..4827c17cb2702fbcbfb9f361a87c3d43939ff00f --- /dev/null +++ b/include/log4qt/helpers/configuratorhelper.h @@ -0,0 +1,169 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_HELPERS_CONFIGURATORHELPER_H +#define LOG4QT_HELPERS_CONFIGURATORHELPER_H + +#include "log4qt/log4qtshared.h" +#include "log4qt/loggingevent.h" + +#include +#include +#include +#include + +class QFileSystemWatcher; + +namespace Log4Qt +{ + +/*! + * \brief The class ConfiguratorHelper provides a confiuration file watch + * and last error for configurator classes. + * + * A configuration file can be set using setConfigurationFile(). The file + * is watched for changes. If a change occurs the configuration is reloaded + * and the ConfigurationFileChanged() signal is Q_EMITted. Error information + * for the last call to a configure function or the last configuration file + * change can be accessed using configureError(). + * + * \note All the functions declared in this class are thread-safe. + */ +class LOG4QT_EXPORT ConfiguratorHelper : public QObject +{ + Q_OBJECT + +public: + /*! + * Prototype for a configure callback function. The function is called + * when then configuration file is changed and takes the + * configuration file as a parameter. + * + * \sa setConfigurationFile(), + * PropertyConfigurator::configure(const QString &) + */ + typedef bool (*ConfigureFunc)(const QString &fileName); + +private: + ConfiguratorHelper(QObject *parent = nullptr); + virtual ~ConfiguratorHelper(); + + Q_DISABLE_COPY(ConfiguratorHelper) + +public: + + /*! + * Returns the error information for the last configuration operation + * that took place. The configuration operation could be the result of + * a call to one of the configure methods or through a change + * to the configuration file. + * + * \sa setConfigureError(), PropertyConfigurator::configure(), + * setConfigurationFile() + */ + static QList configureError(); + + /*! + * Returns the current configuration file. + * + * \sa setConfigurationFile() + */ + static QString configurationFile(); + + /*! + * Returns the ConfiguratorHelper instance. + */ + static ConfiguratorHelper *instance(); + + /*! + * Sets the configuration error information for the last configuration + * operation. + * + * \sa configureError() + */ + static void setConfigureError(const QList &configureError); + + /*! + * Sets the configuration file to \a fileName. The file is watched for + * changes. On a file change the function \a pConfigureFunc will be called + * and the signal configurationFileChange() will be Q_EMITted. + * + * Setting the configuration file to an empty string stops the file watch. + * + * \sa configurationFile(), PropertyConfigurator::configureAndWatch(), + * configureError() + */ + static void setConfigurationFile(const QString &fileName = QString(), + ConfigureFunc pConfigureFunc = nullptr); + +Q_SIGNALS: + /*! + * The signal is Q_EMITted after a change to the file \a fileName + * was processed. If an error occured during the configuration, the + * flag \a error will be true and error information is available + * over configureError(). + */ + void configurationFileChanged(const QString &fileName, + bool error); + +private Q_SLOTS: + void doConfigurationFileChanged(const QString &fileName); + void doConfigurationFileDirectoryChanged(const QString &path); + void tryToReAddConfigurationFile(); + +private: + void doSetConfigurationFile(const QString &fileName, + ConfigureFunc pConfigureFunc); + +private: + mutable QMutex mObjectGuard; + QFileInfo mConfigurationFile; + ConfigureFunc mConfigureFunc; + QFileSystemWatcher *mConfigurationFileWatch; + QList mConfigureError; +}; + +inline QList ConfiguratorHelper::configureError() +{ + QMutexLocker locker(&instance()->mObjectGuard); + return instance()->mConfigureError; +} + +inline QString ConfiguratorHelper::configurationFile() +{ + QMutexLocker locker(&instance()->mObjectGuard); + return instance()->mConfigurationFile.absoluteFilePath(); +} + +inline void ConfiguratorHelper::setConfigureError(const QList &configureError) +{ + QMutexLocker locker(&instance()->mObjectGuard); + instance()->mConfigureError = configureError; +} + +inline void ConfiguratorHelper::setConfigurationFile(const QString &fileName, + ConfigureFunc pConfigureFunc) +{ + instance()->doSetConfigurationFile(fileName, pConfigureFunc); +} + +} // namespace Log4Qt + +#endif // LOG4QT_HELPERS_CONFIGURATORHELPER_H diff --git a/include/log4qt/helpers/datetime.h b/include/log4qt/helpers/datetime.h new file mode 100644 index 0000000000000000000000000000000000000000..2b4c74759cb031fefec57d599b400728824f634b --- /dev/null +++ b/include/log4qt/helpers/datetime.h @@ -0,0 +1,156 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_HELPERS_DATETIME_H +#define LOG4QT_HELPERS_DATETIME_H + +#include "log4qt/log4qtshared.h" + +#include + +namespace Log4Qt +{ + +/*! + * \brief The class DateTime provides extended functionality for QDateTime. + * + * The class DateTime implements additional formatting options for + * toString() and provides conversion functions from and to milliseconds. + */ +class LOG4QT_EXPORT DateTime : public QDateTime +{ +public: + /*! + * Constructs a null date time. + * + * \sa QDateTime::QDateTime() + */ + DateTime(); + + ~DateTime(); + + /*! + * Constructs a copy of another QDateTime. + * + * \sa QDateTime::QDateTime(const QDateTime &other) + */ + DateTime(const QDateTime &other); + + DateTime(const DateTime &other); + + /*! + * Constructs a datetime with the given \a date and \a time, using + * the time specification defined by \a timeSpec. + * + * \sa QDateTime::QDateTime(const QDate &date, const QTime &time, + * Qt::TimeSpec timeSpec = Qt::LocalTime) + */ + DateTime(QDate date, + QTime time, + Qt::TimeSpec timeSpec = Qt::LocalTime); + + /*! + * Assigns \a other to this DateTime and returns a reference to it. + */ + DateTime &operator=(const DateTime &other); + + /*! + * Returns the datetime as a string. The \a format parameter + * determines the format of the result string. + * + * + * Alternatively the \a format parameter can specify one of the + * following strings. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
String Format
ABSOLUTE uses the format HH:mm:ss.zzz
DATE uses the format dd MMM YYYY HH:mm:ss.zzz
ISO8601 uses the format yyyy-MM-dd hh:mm:ss.zzz
NONE uses an empty string as format
RELATIVE returns the milliseconds since start of the program
+ * + * \sa QDateTime::toString(const QString &format) + */ + QString toString(const QString &format) const; + + /*! + * Returns the current datetime, as reported by the system clock, in + * the local time zone. + * + * \sa QDateTime::currentDateTime() + */ + static DateTime currentDateTime(); + static DateTime fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec, int offsetSeconds = 0); + static DateTime fromMSecsSinceEpoch(qint64 msecs); + +private: + QString formatDateTime(const QString &format) const; +}; + +inline DateTime::DateTime(const QDateTime &other) : QDateTime(other) +{} + +inline DateTime::DateTime(QDate date, + QTime time, + Qt::TimeSpec timeSpec) : + QDateTime(date, time, timeSpec) +{} + +inline DateTime &DateTime::operator=(const DateTime &other) +{ + QDateTime::operator=(other); + return *this; +} + +inline DateTime DateTime::currentDateTime() +{ + return DateTime(QDateTime::currentDateTime()); +} + +inline DateTime DateTime::fromMSecsSinceEpoch(qint64 msecs) +{ + return DateTime(QDateTime::fromMSecsSinceEpoch(msecs)); +} + +inline DateTime DateTime::fromMSecsSinceEpoch(qint64 msecs, Qt::TimeSpec spec, int offsetSeconds) +{ + return DateTime(QDateTime::fromMSecsSinceEpoch(msecs, spec, offsetSeconds)); +} + +} // namespace Log4Qt + +Q_DECLARE_TYPEINFO(Log4Qt::DateTime, Q_MOVABLE_TYPE); + +#endif // LOG4QT_HELPERS_DATETIME_H diff --git a/include/log4qt/helpers/dispatcher.h b/include/log4qt/helpers/dispatcher.h new file mode 100644 index 0000000000000000000000000000000000000000..4fc3d1549519aa953e0e6bd8cb4365a3114e3c93 --- /dev/null +++ b/include/log4qt/helpers/dispatcher.h @@ -0,0 +1,56 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QTDISPATCHER_H +#define LOG4QTDISPATCHER_H + +#include + +namespace Log4Qt +{ + +class AsyncAppender; + +/*! + * \brief The class Dispatcher does the actual logging to the attached appanders. + * + * The Dispatcher is the worker object which class the attached apperders in the + * the context of the DispatcherThread. + * + * \note All the functions declared in this class are thread-safe. + */ +class Dispatcher : public QObject +{ + Q_OBJECT +public: + explicit Dispatcher(QObject *parent = nullptr); + + void setAsyncAppender(AsyncAppender *asyncAppender); + +protected: + void customEvent(QEvent *event) override; + +private: + AsyncAppender *mAsyncAppender; +}; + +} // namespace Log4Qt + +#endif // DISPATCHER_H diff --git a/include/log4qt/helpers/factory.h b/include/log4qt/helpers/factory.h new file mode 100644 index 0000000000000000000000000000000000000000..6123ffa1cc41eafec4246ef353381e0977f7f230 --- /dev/null +++ b/include/log4qt/helpers/factory.h @@ -0,0 +1,432 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_HELPERS_FACTORY_H +#define LOG4QT_HELPERS_FACTORY_H + +#include "log4qt/log4qtshared.h" + +#include +#include +#include + +class QObject; +class QMetaProperty; + +namespace Log4Qt +{ + +class Appender; +class Filter; +class Layout; + +/*! + * \brief The class Factory provides factories for Appender, Filter and + * Layout objects. + * + * The functions createAppender(), createFilter() and createLayout() + * allow to create objects by specifying their class names. By default + * all classes of the package are recognised with their Log4j and Log4Qt + * classanmes. For example an object of the class FileAppender can be + * craeted using "org.apache.log4j.FileAppender" or "Log4Qt::FileAppender". + * Additional classes can be registered using registerAppender(), + * registerFilter() and registerLayout(). + * + * An QObject property can be set from a string value with + * setObjectProperty(). The function handles the required error checking + * and type conversion. + * + * \note All the functions declared in this class are thread-safe. + * + * \sa PropertyConfigurator + */ +class LOG4QT_EXPORT Factory +{ +public: + /*! + * Prototype for an Appender factory function. The function creates + * an Appender object on the heap and returns a pointer to it. + * + * \sa registerAppender(), createAppender() + */ + typedef Appender *(*AppenderFactoryFunc)(); + + /*! + * Prototype for a Filter factory function. The function creates + * a Filter object on the heap and returns a pointer to it. + * + * \sa registerFilter(), createFilter() + */ + typedef Filter *(*FilterFactoryFunc)(); + + /*! + * Prototype for a Layout factory function. The function creates + * a Layout object on the heap and returns a pointer to it. + * + * \sa registerLayout(), createLayout() + */ + typedef Layout *(*LayoutFactoryFunc)(); + +private: + Factory(); + Q_DISABLE_COPY(Factory) + +public: + /*! + * Creates an object for the class \a appenderClassName on the heap + * and returns a pointer to it. If the class has no registered factory + * function a null pointer is returned. + * + * \sa registerAppender(), unregisterAppender(), registeredAppenders() + */ + static Appender *createAppender(const QString &appenderClassName); + + /*! + * This is an overloaded member function, provided for convenience. + */ + static Appender *createAppender(const char *appenderClassName); + + /*! + * Creates an object for the class \a filterClassName on the heap + * and returns a pointer to it. If the class has no registered factory + * function a null pointer is returned. + * + * \sa registerFilter(), unregisterFilter(), registeredFilters() + */ + static Filter *createFilter(const QString &filterClassName); + + /*! + * This is an overloaded member function, provided for convenience. + */ + static Filter *createFilter(const char *filterClassName); + + /*! + * Creates an object for the class \a layoutClassName on the heap + * and returns a pointer to it. If the class has no registered factory + * function a null pointer is returned. + * + * \sa registerLayout(), unregisterLayout(), registeredLayouts() + */ + static Layout *createLayout(const QString &layoutClassName); + + /*! + * This is an overloaded member function, provided for convenience. + */ + static Layout *createLayout(const char *layoutClassName); + + /*! + * Returns the Factory instance. + */ + static Factory *instance(); + + /*! + * Registers the Appender factory function \a appenderFactoryFunc + * for the class \a appenderClassName. If a registered factory + * function exists for the class, it is replaced with + * \a appenderFactoryFunc. + * + * \sa unregisterAppender(), registeredAppenders(), createAppender() + */ + static void registerAppender(const QString &appenderClassName, + AppenderFactoryFunc appenderFactoryFunc); + + /*! + * This is an overloaded member function, provided for convenience. + */ + static void registerAppender(const char *appenderClassName, + AppenderFactoryFunc appenderFactoryFunc); + + /*! + * Registers the Filter factory function \a filterFactoryFunc + * for the class \a filterClassName. If a registered factory + * function exists for the class, it is replaced with + * \a filterFactoryFunc. + * + * \sa unregisterFilter(), registeredFilters(), createFilter() + */ + static void registerFilter(const QString &filterClassName, + FilterFactoryFunc filterFactoryFunc); + + /*! + * This is an overloaded member function, provided for convenience. + */ + static void registerFilter(const char *filterClassName, + FilterFactoryFunc filterFactoryFunc); + + /*! + * Registers the Layout factory function \a layoutFactoryFunc + * for the class \a filterClassName. If a registered factory + * function exists for the class, it is replaced with + * \a layoutFactoryFunc. + * + * \sa unregisterLayout(), registeredLayout(), createLayout() + */ + static void registerLayout(const QString &layoutClassName, + LayoutFactoryFunc layoutFactoryFunc); + + /*! + * This is an overloaded member function, provided for convenience. + */ + static void registerLayout(const char *layoutClassName, + LayoutFactoryFunc layoutFactoryFunc); + + /*! + * Returns a list of the class names for registered Appender factory + * functions. + * + * \sa registerAppender(), unregisterAppender() + */ + static QStringList registeredAppenders(); + + /*! + * Returns a list of the class names for registered Filter factory + * functions. + * + * \sa registerFilter(), unregisterFilter() + */ + static QStringList registeredFilters(); + + /*! + * Returns a list of the class names for registered Layout factory + * functions. + * + * \sa registerLayout(), unregisterLayout() + */ + static QStringList registeredLayouts(); + + /*! + * Sets the property \a rProperty of the object \a pObject to the + * value \a rValue. The function will test that the property + * \a rProperty is writeable and of a type the function can convert to. + * The types bool, int, Level and QString are supported. + * + * \sa OptionConverter + */ + static void setObjectProperty(QObject *object, + const QString &property, + const QString &value); + + /*! + * This is an overloaded member function, provided for convenience. + */ + static void setObjectProperty(QObject *object, + const char *property, + const QString &value); + + /*! + * Unregisters the Appender factory function for the class + * \a rAppenderClassName. + * + * \sa registerAppender(), registeredAppenders() + */ + static void unregisterAppender(const QString &appenderClassName); + + /*! + * This is an overloaded member function, provided for convenience. + */ + static void unregisterAppender(const char *appenderClassName); + + /*! + * Unregisters the Filter factory function for the class + * \a filterClassName. + * + * \sa registerFilter(), registeredFilters() + */ + static void unregisterFilter(const QString &filterClassName); + + /*! + * This is an overloaded member function, provided for convenience. + */ + static void unregisterFilter(const char *filterClassName); + + /*! + * Unregisters the Layout factory function for the class + * \a filterClassName. + * + * \sa registerLayout(), registeredLayouts() + */ + static void unregisterLayout(const QString &filterClassName); + + /*! + * This is an overloaded member function, provided for convenience. + */ + static void unregisterLayout(const char *layoutClassName); + +private: + Appender *doCreateAppender(const QString &appenderClassName); + Filter *doCreateFilter(const QString &filterClassName); + Layout *doCreateLayout(const QString &layoutClassName); + void doRegisterAppender(const QString &appenderClassName, + AppenderFactoryFunc appenderFactoryFunc); + void doRegisterFilter(const QString &filterClassName, + FilterFactoryFunc filterFactoryFunc); + void doRegisterLayout(const QString &filterClassName, + LayoutFactoryFunc layoutFactoryFunc); + void doSetObjectProperty(QObject *object, + const QString &property, + const QString &value); + void doUnregisterAppender(const QString &appenderClassName); + void doUnregisterFilter(const QString &filterClassName); + void doUnregisterLayout(const QString &filterClassName); + void registerDefaultAppenders(); + void registerDefaultFilters(); + void registerDefaultLayouts(); + bool validateObjectProperty(QMetaProperty &metaProperty, + const QString &property, + QObject *object); + +private: + mutable QMutex mObjectGuard; + QHash mAppenderRegistry; + QHash mFilterRegistry; + QHash mLayoutRegistry; +}; + +inline Appender *Factory::createAppender(const QString &appenderClassName) +{ + return instance()->doCreateAppender(appenderClassName); +} + +inline Appender *Factory::createAppender(const char *appenderClassName) +{ + return instance()->doCreateAppender(QLatin1String(appenderClassName)); +} + +inline Filter *Factory::createFilter(const QString &filterClassName) +{ + return instance()->doCreateFilter(filterClassName); +} + +inline Filter *Factory::createFilter(const char *layoutClassName) +{ + return instance()->doCreateFilter(QLatin1String(layoutClassName)); +} + +inline Layout *Factory::createLayout(const QString &layoutClassName) +{ + return instance()->doCreateLayout(layoutClassName); +} + +inline Layout *Factory::createLayout(const char *layoutClassName) +{ + return instance()->doCreateLayout(QLatin1String(layoutClassName)); +} + +inline void Factory::registerAppender(const QString &appenderClassName, + AppenderFactoryFunc appenderFactoryFunc) +{ + instance()->doRegisterAppender(appenderClassName, appenderFactoryFunc); +} + +inline void Factory::registerAppender(const char *appenderClassName, + AppenderFactoryFunc appenderFactoryFunc) +{ + instance()->doRegisterAppender(QLatin1String(appenderClassName), appenderFactoryFunc); +} + +inline void Factory::registerFilter(const QString &filterClassName, + FilterFactoryFunc filterFactoryFunc) +{ + instance()->doRegisterFilter(filterClassName, filterFactoryFunc); +} + +inline void Factory::registerFilter(const char *filterClassName, + FilterFactoryFunc filterFactoryFunc) +{ + instance()->doRegisterFilter(QLatin1String(filterClassName), filterFactoryFunc); +} + +inline void Factory::registerLayout(const QString &filterClassName, + LayoutFactoryFunc layoutFactoryFunc) +{ + instance()->doRegisterLayout(filterClassName, layoutFactoryFunc); +} + +inline void Factory::registerLayout(const char *layoutClassName, + LayoutFactoryFunc layoutFactoryFunc) +{ + instance()->doRegisterLayout(QLatin1String(layoutClassName), layoutFactoryFunc); +} + +inline QStringList Factory::registeredAppenders() +{ + QMutexLocker locker(&instance()->mObjectGuard); + return instance()->mAppenderRegistry.keys(); +} + +inline QStringList Factory::registeredFilters() +{ + QMutexLocker locker(&instance()->mObjectGuard); + return instance()->mFilterRegistry.keys(); +} + +inline QStringList Factory::registeredLayouts() +{ + QMutexLocker locker(&instance()->mObjectGuard); + return instance()->mLayoutRegistry.keys(); +} + +inline void Factory::setObjectProperty(QObject *object, + const QString &property, + const QString &value) +{ + instance()->doSetObjectProperty(object, property, value); +} + +inline void Factory::setObjectProperty(QObject *object, + const char *property, + const QString &value) +{ + instance()->doSetObjectProperty(object, QLatin1String(property), value); +} + +inline void Factory::unregisterAppender(const QString &appenderClassName) +{ + instance()->doUnregisterAppender(appenderClassName); +} + +inline void Factory::unregisterAppender(const char *appenderClassName) +{ + instance()->doUnregisterAppender(QLatin1String(appenderClassName)); +} + +inline void Factory::unregisterFilter(const QString &filterClassName) +{ + instance()->doUnregisterFilter(filterClassName); +} + +inline void Factory::unregisterFilter(const char *filterClassName) +{ + instance()->doUnregisterFilter(QLatin1String(filterClassName)); +} + +inline void Factory::unregisterLayout(const QString &filterClassName) +{ + instance()->doUnregisterLayout(filterClassName); +} + +inline void Factory::unregisterLayout(const char *layoutClassName) +{ + instance()->doUnregisterLayout(QLatin1String(layoutClassName)); +} + +} // namespace Log4Qt + +#endif // LOG4QT_HELPERS_FACTORY_H diff --git a/include/log4qt/helpers/initialisationhelper.h b/include/log4qt/helpers/initialisationhelper.h new file mode 100644 index 0000000000000000000000000000000000000000..9e194c1327d6eab616c10307b8017772a166d029 --- /dev/null +++ b/include/log4qt/helpers/initialisationhelper.h @@ -0,0 +1,231 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_HELPERS_INITIALISATIONHELPER_H +#define LOG4QT_HELPERS_INITIALISATIONHELPER_H + +#include "log4qt/log4qtshared.h" + +#include +#include + +class QMutex; + +namespace Log4Qt +{ + +/*! + * LOG4QT_IMPLEMENT_INSTANCE implements an instance function for a + * singleton class \a TYPE. + * + * + * The following example illustrates how to use the macro to create a + * singleton class: + * + * \code + * #file: mysingleton.h + * + * class MySingleton + * { + * private: + * MySingleton(); + * ~MySingleton(); + * public: + * MySingleton *instance(); + * } + * \endcode + * \code + * #file: mysingleton.cpp + * + * #include mysingleton.h + * + * MySingleton::MySingleton() + * {} + * + * MySingleton::~MySingleton() + * {} + * + * LOG4QT_IMPLEMENT_INSTANCE(MySingleton) + * + * \endcode + * + * \note The function created by the macro is thread-safe. + * + * \sa \ref Log4Qt::InitialisationHelper "InitialisationHelper" + */ +#define LOG4QT_IMPLEMENT_INSTANCE(TYPE) \ + TYPE *TYPE::instance() \ + { \ + static auto * singelton(new TYPE); \ + return singelton; \ + } + +/*! + * \brief The class InitialisationHelper performs static initialisation + * tasks. + * + * The InitialisationHelper is either created on the first call or through + * static initialisation. It will capture the programs startup time, + * which can be retrieved using startTime(). The system environment + * is analysed for package related definitions. The result is available + * over environmentSettings(). The packages custom types are registered with + * the Qt type system. + * + * Settings for the package can be retrieved using setting(). Two macros + * are available to help with the creation of singletons / global static + * objects and \ref Log4Qt::LOG4QT_IMPLEMENT_INSTANCE "LOG4QT_IMPLEMENT_INSTANCE"). + * + * \note All the functions declared in this class are thread-safe. + * + * \sa \ref Init "Initialization procedure", + */ +class LOG4QT_EXPORT InitialisationHelper +{ +private: + InitialisationHelper(); + virtual ~InitialisationHelper(); + + Q_DISABLE_COPY(InitialisationHelper) + +public: + + /*! + * Returns a hash with the settings retrieved from the system + * environment on startup. + * + * The following table shows the environment variables taken into + * account and the setting key used for them. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Environment variable Setting key
LOG4QT_DEBUG Debug
LOG4QT_DEFAULTINITOVERRIDE DefaultInitOverride
LOG4QT_CONFIGURATION Configuration
+ * + * \sa \ref Env "Environment Variables", + * setting() + */ + static QHash environmentSettings(); + + /*! + * Returns the InitialisationHelper instance. + */ + static InitialisationHelper *instance(); + + /*! + * Returns the value for the setting \a rKey or \a rDefault, if it is + * not defined. + * + * A setting can be either defined by an environment variable or by a + * key in the application setting. The function will first test the + * settings made by environment variables for the key \a rKey using + * environmentSettings(). If the key is not present and a + * QCoreApplication exists, the application settings are tested for + * the key \a rKey in the group \c %Log4Qt. + * + * The following setting exists: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Setting key Description
Debug The variable controls the Level value for the logger + * LogManager::logLogger(). If the value is a valid Level string, + * the level for the logger is set to the level. If the value is not + * a valid Level string, \ref Level::DEBUG_INT "DEBUG_INT" is used. + * Otherwise \ref Level::ERROR_INT "ERROR_INT" is used.
DefaultInitOverride The variable controls the \ref Init "initialization procedure" + * performed by the \ref LogManager "LogManager" on startup. + * If it is set to any other value then \c false the \ref Init + * "initialization procedure" is skipped.
Configuration Specifies the configuration file used for initialising the package.
ConfiguratorClass Specifies the configurator class used for initialising the package.
+ * + * \sa environmentSettings(), \ref Env "Environment Variables", + * \ref Init "Initialization procedure", + * LogManager::configureLogLogger(), LogManager::startup() + */ + static QString setting(const QString &key, + const QString &defaultValue = QString()); + + /*! + * Returns the start time of the program as the number of milliseconds + * that have passed since 1970-01-01T00:00:00,000, Coordinated + * Universal Time (Qt::UTC). + * + * \sa DateTime::fromMilliSeconds(), + * DateTime::toMilliSeconds() + */ + static qint64 startTime(); + +private: + void doInitialiseEnvironmentSettings(); + void doRegisterTypes(); + QString doSetting(const QString &key, + const QString &defaultValue) const; + static bool shutdown(); + static bool staticInitialisation(); + +private: + const qint64 mStartTime; + QHash mEnvironmentSettings; + static bool mStaticInitialisation; + +}; + +inline QHash InitialisationHelper::environmentSettings() +{ + return instance()->mEnvironmentSettings; +} + +inline QString InitialisationHelper::setting(const QString &key, + const QString &defaultValue) +{ + return instance()->doSetting(key, defaultValue); +} + +inline qint64 InitialisationHelper::startTime() +{ + return instance()->mStartTime; +} + +} // namespace Log4Qt + +#endif // LOG4QT_HELPERS_INITIALISATIONHELPER_H diff --git a/include/log4qt/helpers/logerror.h b/include/log4qt/helpers/logerror.h new file mode 100644 index 0000000000000000000000000000000000000000..6ab7d25d6ec5cbbf81c807dca6052319876902c2 --- /dev/null +++ b/include/log4qt/helpers/logerror.h @@ -0,0 +1,547 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_LOGERROR_H +#define LOG4QT_LOGERROR_H + +#include "log4qt/log4qtshared.h" + +#include +#include + +namespace Log4Qt +{ +/*! + * Creates an LogError object with the error message \a message, the error + * code \a code and the context \a context. The symbol of the error is + * set to \a code as string value. + * + * The following example logs an error, if a character is not a digit. + * + * \code + * if (!c.isDigit()) + * { + * Error e = LOG4QT_ERROR(QT_TR_NOOP("Found character '%1' where digit was expected."), + * LAYOUT_EXPECTED_DIGIT_ERROR, + * "Log4Qt::PatternFormatter"); + * e << QString(c); + * logger()->error(e); + * } + * \endcode + */ +#define LOG4QT_ERROR(message, code, context) \ + LogError(message, code, #code, context) + +/*! + * Creates an LogError object with the error message \a message and the + * error code \a code. The symbol of the error is set to \a code as string + * value. The context is set to the class name of the current object. The + * current objects class must be derived from QObject. + * + * The following example handles an error while opening a file. + * + * \code + * if (!mpFile->open(mode)) + * { + * LogError e = LOG4QT_QCLASS_ERROR(QT_TR_NOOP("Unable to open file '%1' for appender '%2'"), + * APPENDER_OPENING_FILE_ERROR); + * e << mFileName << name(); + * e.addCausingError(LogError(mpFile->errorString(), mpFile->error())); + * logger()->error(e); + * return; + * } + * \endcode + */ +#define LOG4QT_QCLASS_ERROR(message, code) \ + LogError(message, code, #code, this->metaObject()->className()) + +/*! + * \brief The class LogError represents an error. + * + * The class error allows storing error information in a structured way. + * The error message is stored separately from the information that may be + * substituted into the message string. This way it is possible to access + * all information after the error has been raised. It also allows to + * translate the error at a later point in time or to get a translated and + * a not translated error text (e.g. translated for the UI and not + * translated for a log). + * + * The message is accessed using message() and setMessage(). Arguments for + * the message can be added using addArg() or operator<<(). The arguments + * can be retrieved using args(). The message with substituted arguments + * is returned by messageWithArgs(). + * + * An error code can be set as integer value code() and/or a symbolic value + * symbol(). + * + * To allow the translation of the message the error stores the translation + * context (context(), setContext()). The translated message can be accessed + * using translatedMessage() or using translatedMessageWithArgs(), if it + * should contain the arguments. + * + * An error can have one or more related errors that caused it. An error is + * related using addCausingError(). All causing errors can be retrieved using + * causingErrors(). + * + * A per thread error can be maintained using lastError() and setLastError(). + * + * There are two macros avaiable to simplify the error creation. The macro + * \ref Log4Qt::LOG4QT_ERROR "LOG4QT_ERROR" is used with classes not derived + * from QObject. The macro \ref Log4Qt::LOG4QT_QCLASS_ERROR "LOG4QT_QCLASS_ERROR" + * is used with classes derived from QObject. + */ +class LOG4QT_EXPORT LogError +{ +public: + + /*! + * The enum Encoding defines the 8-bit encoding of a character string + * arguments to \ref LogError::LogError(const char *, int, const char *, + * const char *, Encoding) "LogError::LogError()". + * + * \sa \ref LogError::LogError(const char *, int, const char *, const char *, Encoding) "LogError::LogError()" + */ + enum Encoding + { + /*! LATIN-1 */ + LATIN1, + /*! + * The encoding specified by QTextCodec::codecForTr() + * (Latin-1 if none has been set). + */ + CODECFORTR, + /*! UTF-8 */ + UNICODEUTF8 + }; + + /*! + * Creates an empty error. The error code is set to 0 and all other + * members are set to be empty. + * + * \sa isEmpty() + */ + LogError(); + + /*! + * Creates an error with the Message \a message and the error code + * \a code. The symbol for the error code is set to \a rSymbol and the + * context to \a rContext. + * + * \a rContext must be string that can be converted to Latin-1. The + * Latin-1 representation of the string is used with + * QApplication::translate(), if a translation for \a message is + * requested. + * + * \sa translatedMessage(), translatedMessageWithArgs() + */ + explicit LogError(const QString &message, + int code = 0, + const QString &symbol = QString(), + const QString &context = QString()); + + /*! + * Creates an error with the Message \a pMessage and the error code + * \a code. The symbol for the error code is set to \a pSymbol and the + * context to \a pContext. + * + * \a encoding specifies the encoding of \a pMessage. \a pSymbol and + * \a pContext are expected to be Latin-1. + * + * \note To support the macros \ref Log4Qt::LOG4QT_ERROR "LOG4QT_ERROR" + * and \ref Log4Qt::LOG4QT_QCLASS_ERROR "LOG4QT_QCLASS_ERROR" + * the function tests, if \a pSymbol is the string representation of + * \a code. If it is, the symbol is set to be empty. Otherwise symbol + * is set to \a pSymbol. + * + * \sa translatedMessage(), translatedMessageWithArgs() + */ + explicit LogError(const char *message, + int code = 0, + const char *symbol = nullptr, + const char *context = nullptr, + Encoding encoding = LATIN1); + + /*! + * Returns the error code. + * + * \sa setCode() + */ + int code() const; + + /*! + * Returns the context for the error. + * + * \sa setContext() + */ + QString context() const; + + /*! + * Returns the error message. + * + * \sa setMessage() + */ + QString message() const; + + /*! + * Returns the symbol for the error code. + * + * \sa setSymbol() + */ + QString symbol() const; + + /*! + * Returns the translated error message. + * + * The translated message is created by calling + * QCoreApplication::translate() using context().toLatin1() as + * context and message.toUtf8() as message. + * + * \sa translatedMessageWithArgs() + */ + QString translatedMessage() const; + + /*! + * Sets the error code to \a code. + * + * \sa code() + */ + void setCode(int code); + + /*! + * Sets the context to \a className. + * + * \a rContext must be string that can be converted to Latin-1. The + * Latin-1 representation of the string is used with + * QApplication::translate(), if a translation for \a message is + * requestd. + * + * \sa context(), translatedMessage(), translatedMessageWithArgs() + */ + void setContext(const QString &className); + + /*! + * Sets the error message to \a message + * + * \sa message() + */ + void setMessage(const QString &message); + + /*! + * Sets the symbol for the error code to \a symbol. + * + * \sa symbol() + */ + void setSymbol(const QString &symbol); + + /*! + * Returns the last error set for the current thread using + * setLastError(). + * + * \note: This function is thread-safe. + * + * \sa setLastError() + */ + static LogError lastError(); + + /*! + * Sets the last error for the current thread to \a logError. + * + * \note: This function is thread-safe. + * + * \sa lastError() + */ + static void setLastError(const LogError &logError); + + /*! + * Appends \a rArg to the list of arguments and returns a reference to + * this error. + * + * \sa operator<<(), args(), clearArgs() + */ + LogError &addArg(const QVariant &arg); + + /*! + * This is an overloaded member function, provided for convenience. + */ + LogError &addArg(int arg); + + /*! + * This is an overloaded member function, provided for convenience. + */ + LogError &addArg(const QString &arg); + + /*! + * Appends \a logError to the list of causing errors and returns a + * reference to this error. + * + * \sa causingErrors(), clearCausingErrors() + */ + LogError &addCausingError(const LogError &logError); + + /*! + * Returns the list of arguments that have been added to this error. + * + * \sa addArg(), operator<<(), clearArgs() + */ + QList args() const; + + /*! + * Returns the list of causing errors that have been added to this error. + * + * \sa addArg(), operator<<(), clearArgs() + */ + QList causingErrors() const; + + /*! + * Clears the list of arguments that have been added to this error. + * + * \sa addArg(), operator<<(), args() + */ + void clearArgs(); + + /*! + * Clears the list of causing errors that have been added to this error. + * + * \sa addCausingError(), causingErrors() + */ + void clearCausingErrors(); + + /*! + * Returns true, if the error code is 0 and the message is empty. + * Otherwise it returns false. + * + * \sa code(), message() + */ + bool isEmpty() const; + + /*! + * Returns the message with arguments. The arguments are incoorporated + * into the messag using QString::arg(). + * + * \sa QString::arg(), translatedMessageWithArgs() + */ + QString messageWithArgs() const; + + /*! + * Returns the translated message with arguments. The arguments are + * incoorporated into the messag using QString::arg(). + * + * \sa QString::arg(), messageWithArgs(), translatedMessage() + */ + QString translatedMessageWithArgs() const; + + /*! + * Appends \a rArg to the list of arguments and returns a reference to + * this error. + * + * \sa addArg() + */ + LogError &operator<<(const QVariant &arg); + + /*! + * This is an overloaded member function, provided for convenience. + */ + LogError &operator<<(int arg); + + /*! + * This is an overloaded member function, provided for convenience. + */ + LogError &operator<<(const QString &arg); + + /*! + * Returns a string representation of the error. + * + * The string has the following format: + * + * + * message (context::symbol, code): causing_error, causing_error + * + * + * If members are empty they are omitted: + * - Omit context, if empty + * - Omit symbol, if empty + * - Omit double colon with context and symbol, if both are empty + * - Omit code, if 0 + * - Omit bracket with context/symbol and code, if all are empty + * - Omit colon with causing errors, if no causing errors exist + */ + QString toString() const; + +private: + QString insertArgs(const QString &message) const; + QString cleanMessage(const QString &message); + +private: + int mCode; + QString mContext; + QString mMessage; + QString mSymbol; + QList mArgs; + QList mCausingErrors; + +#ifndef QT_NO_DATASTREAM + // Needs to be friend to stream objects + friend QDataStream &operator<<(QDataStream &stream, + const LogError &logError); + friend QDataStream &operator>>(QDataStream &stream, + LogError &logError); +#endif // QT_NO_DATASTREAM +}; + +#ifndef QT_NO_DATASTREAM +/*! + * \relates LogError + * + * Writes the given error \a logError to the given stream \a rStream, + * and returns a reference to the stream. + */ +QDataStream &operator<<(QDataStream &stream, + const LogError &logError); + +/*! + * \relates LogError + * + * Reads an error from the given stream \a rStream into the given + * error \a logError, and returns a reference to the stream. + */ +QDataStream &operator>>(QDataStream &stream, + LogError &logError); +#endif // QT_NO_DATASTREAM + +inline int LogError::code() const +{ + return mCode; +} + +inline QString LogError::context() const +{ + return mContext; +} + +inline QString LogError::message() const +{ + return mMessage; +} + +inline QString LogError::symbol() const +{ + return mSymbol; +} + +inline void LogError::setCode(int code) +{ + mCode = code; +} + +inline void LogError::setContext(const QString &context) +{ + mContext = context; +} + +inline void LogError::setMessage(const QString &message) +{ + mMessage = cleanMessage(message); +} + +inline void LogError::setSymbol(const QString &symbol) +{ + mSymbol = symbol; +} + +inline LogError &LogError::addArg(const QVariant &arg) +{ + mArgs << arg; + return *this; +} + +inline LogError &LogError::addArg(int arg) +{ + mArgs << QVariant(arg); + return *this; +} + +inline LogError &LogError::addArg(const QString &arg) +{ + mArgs << QVariant(arg); + return *this; +} + +inline LogError &LogError::addCausingError(const LogError &logError) +{ + mCausingErrors << logError; + return *this; +} + +inline QList LogError::args() const +{ + return mArgs; +} + +inline void LogError::clearArgs() +{ + mArgs.clear(); +} + +inline void LogError::clearCausingErrors() +{ + mCausingErrors.clear(); +} + +inline QList LogError::causingErrors() const +{ + return mCausingErrors; +} + +inline bool LogError::isEmpty() const +{ + return mCode || !mMessage.isEmpty(); +} + +inline QString LogError::messageWithArgs() const +{ + return insertArgs(message()); +} + +inline QString LogError::translatedMessageWithArgs() const +{ + return insertArgs(translatedMessage()); +} + +inline LogError &LogError::operator<<(const QVariant &arg) +{ + return addArg(arg); +} + +inline LogError &LogError::operator<<(int arg) +{ + return addArg(arg); +} + +inline LogError &LogError::operator<<(const QString &arg) +{ + return addArg(arg); +} + +} // namespace Log4Qt + +Q_DECLARE_METATYPE(Log4Qt::LogError) +Q_DECLARE_TYPEINFO(Log4Qt::LogError, Q_MOVABLE_TYPE); + +#endif // LOG4QT_ERROR_H diff --git a/include/log4qt/helpers/optionconverter.h b/include/log4qt/helpers/optionconverter.h new file mode 100644 index 0000000000000000000000000000000000000000..6ec9af25cacd1ab260472c4f046b15084f7db94c --- /dev/null +++ b/include/log4qt/helpers/optionconverter.h @@ -0,0 +1,120 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_OPTIONCONVERTER_H +#define LOG4QT_OPTIONCONVERTER_H + +#include "log4qt/log4qtshared.h" +#include "log4qt/level.h" + +#include + +namespace Log4Qt +{ +class Properties; + +/*! + * \brief The class OptionConverter provides functions to convert strings + * to property values. + */ +class LOG4QT_EXPORT OptionConverter +{ +private: + OptionConverter(); + Q_DISABLE_COPY(OptionConverter) +public: + static QString findAndSubst(const Properties &properties, + const QString &key); + + /*! + * Returns the JAVA class name \a className as C++ class name by + * replacing all . characters with ::. + */ + static QString classNameJavaToCpp(const QString &className); + + /*! + * Converts the option \a option to a boolean value. Valid strings + * for true are "true", "enabled" and "1". Valid strings + * for false are "false", "disabled" and "0". If the conversion is + * successful, the target is returned and \a ok is set to true. + * Otherwise an error is written to the log, \a ok is set to false + * and false is returned. + */ + static bool toBoolean(const QString &option, + bool *ok = nullptr); + + static bool toBoolean(const QString &option, + bool defaultValue); + + /*! + * Converts the option string \a option to a file size. The string can + * be a positive integer followed by an optional unit suffix "KB", "MB" + * or "GB". If a unit suffix is specified the the integer is + * interpreted as kilobytes, megabytes or gigabytes. If the conversion + * is successful, the size is returned and \a ok is set to true. + * Otherwise an error is written to the log, \a ok is set to false + * and 0 is returned. + */ + static qint64 toFileSize(const QString &option, + bool *ok = nullptr); + + /*! + * Converts the option \a option to a integer value using + * QString::toInt(). If the conversion is successful, the integer is + * returned and \a ok is set to true. Otherwise an error is written + * to the log, \a ok is set to false and 0 is returned. + */ + static int toInt(const QString &option, + bool *ok = nullptr); + + /*! + * Converts the option \a option to a level value using + * Level::fromString(). If the conversion is successful, the level + * is returned and \a ok is set to true. Otherwise an error is + * written to the log, \a ok is set to false and a level with + * the value Level::NULL_INT is returned. + * + * \sa Level::fromString() + */ + static Level toLevel(const QString &option, + bool *ok = nullptr); + + static Level toLevel(const QString &option, + Log4Qt::Level defaultValue); + + /*! + * Converts the option \a option to a ConsoleAppender::Target value. + * Valid strings for \a option are "System.out", "STDOUT_TARGET", + * "System.err" and "STDERR_TARGET". If the conversion is successful, + * the target is returned and \a ok is set to true. Otherwise an + * error is written to the log, \a ok is set to false and + * ConsoleAppender::STDOUT_TARGET is returned. + */ + static int toTarget(const QString &option, + bool *ok = nullptr); +}; + +} // namespace Log4Qt + + +Q_DECLARE_TYPEINFO(Log4Qt::OptionConverter, Q_MOVABLE_TYPE); + + +#endif // LOG4QT_OPTIONCONVERTER_H diff --git a/include/log4qt/helpers/patternformatter.h b/include/log4qt/helpers/patternformatter.h new file mode 100644 index 0000000000000000000000000000000000000000..b1c4d7b537ae33f27229cf52696721df2c706cb6 --- /dev/null +++ b/include/log4qt/helpers/patternformatter.h @@ -0,0 +1,139 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_PATTERNFORMATTER_H +#define LOG4QT_PATTERNFORMATTER_H + +#include "log4qt/log4qtshared.h" + +#include +#include + +namespace Log4Qt +{ + +class FormattingInfo; +class PatternConverter; +class LoggingEvent; + +/*! + * \brief The class PatternFormatter formats a logging event based on a + * pattern string. + * + * The class PatternFormatter formats a LoggingEvent base on a pattern + * string. It is used by the patternLayout and TTCCLayout class to + * implement the formatting. + * + * On object construction the provided patterns tring is parsed. Based on + * the information found a chain of PatternConverter is created. Each + * PatternConverter handles a certain member of a LoggingEvent. + * + * \sa PatternLayout::format() + * \sa TTCCLayout::format() + */ +class LOG4QT_EXPORT PatternFormatter +{ +public: + /*! + * Creates a PatternFormatter using a the specified \a pattern. + */ + PatternFormatter(const QString &pattern); + + /*! + * Destroys the PatternFormatter and all PatternConverter. + */ + virtual ~PatternFormatter(); + +private: + Q_DISABLE_COPY(PatternFormatter) + +public: + /*! + * Formats the given \a loggingEvent using the chain of + * PatternConverter created during construction from the specified + * pattern. + */ + QString format(const LoggingEvent &loggingEvent) const; + +private: + /*! + * If the character \a digit is a digit the digit is added to the + * integer \a value and the function returns true. Otherwise the + * function returns false. + * + * The function adds the digit by multiplying the existing value + * with ten and adding the numerical value of the digit. If the + * maximum integer value would be exceeded by the operation + * \a value is set to INT_MAX. + */ + bool addDigit(QChar digit, + int &value); + + /*! + * Creates a PatternConverter based on the specified conversion + * character \a rChar, the formatting information + * \a formattingInfo and the option \a option. + * + * The PatternConverter converter is appended to the list of + * PatternConverters. + */ + void createConverter(QChar character, + Log4Qt::FormattingInfo formattingInfo, + const QString &option = QString()); + + /*! + * Creates a LiteralPatternConverter with the string literal + * \a literal. + * + * The PatternConverter converter is appended to the list of + * PatternConverters. + */ + void createLiteralConverter(const QString &literal); + + /*! + * Parses the pattern string specified on construction and creates + * PatternConverter according to it. + */ + void parse(); + + /*! + * Parses an integer option from an option string. If the string is + * not a valid integer or the integer value is less then zero, zero + * is returned. Returns the end of line seperator for the operating + * system. + */ + int parseIntegeoption(const QString &option); + +private: + const QString mIgnoreCharacters; + const QString mConversionCharacters; + const QString mOptionCharacters; + QString mPattern; + QList mPatternConverters; +}; + + +} // namespace Log4Qt + + +Q_DECLARE_TYPEINFO(Log4Qt::PatternFormatter, Q_MOVABLE_TYPE); + + +#endif // LOG4QT_PATTERNFORMATTER_H diff --git a/include/log4qt/helpers/properties.h b/include/log4qt/helpers/properties.h new file mode 100644 index 0000000000000000000000000000000000000000..35d6929f85a22a26306a6a59253c1a982ff6c457 --- /dev/null +++ b/include/log4qt/helpers/properties.h @@ -0,0 +1,117 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_PROPERTIES_H +#define LOG4QT_PROPERTIES_H + +#include "log4qt/log4qtshared.h" + +#include +#include + +class QIODevice; +class QSettings; + +namespace Log4Qt +{ +/*! + * \brief The class Properties implements a JAVA property hash. + */ +class LOG4QT_EXPORT Properties : public QHash +{ +public: + Properties(Properties *pDefaultProperties = nullptr); + +public: + Properties *defaultProperties() const; + QString property(const QString &key) const; + QString property(const QString &key, + const QString &defaultValue) const; + void setDefaultProperties(Properties *defaultProperties); + void setProperty(const QString &key, + const QString &value); + + void load(QIODevice *pDevice); + + /*! + * Reads all child keys from the QSettings object \a settings and + * inserts them into this object. The value is created using + * QVariant::toString(). Types that do not support toString() are + * resulting in an empty string. + * + * \code + * QSettings settings; + * settings.setValue("Package", "Full"); + * settings.setValue("Background", Qt::white); + * settings.setValue("Support", true); + * settings.setValue("Help/Language", "en_UK"); + * + * Properties properties + * properties.load(&settings) + * + * // properties (("Package", "Full"), ("Background", ""), ("Support", "true")) + * \endcode + */ + void load(const QSettings &settings); + + QStringList propertyNames() const; + +private: + void parseProperty(const QString &property, + int line); + static int hexDigitValue(QChar digit); + static QString trimLeft(const QString &line); + +private: + Properties *mpDefaultProperties; + static const char msEscapeChar; + static const char *msValueEscapeCodes; + static const char *msValueEscapeChars; + static const char *msKeyEscapeCodes; + static const char *msKeyEscapeChars; +}; + +inline Properties::Properties(Properties *pDefaultProperties) : + mpDefaultProperties(pDefaultProperties) +{} + +inline Properties *Properties::defaultProperties() const +{ + return mpDefaultProperties; +} + +inline void Properties::setDefaultProperties(Properties *defaultProperties) +{ + mpDefaultProperties = defaultProperties; +} + +inline void Properties::setProperty(const QString &key, + const QString &value) +{ + insert(key, value); +} + +} // namespace Log4Qt + + +Q_DECLARE_TYPEINFO(Log4Qt::Properties, Q_MOVABLE_TYPE); + + +#endif // LOG4QT_PROPERTIES_H diff --git a/include/log4qt/hierarchy.h b/include/log4qt/hierarchy.h new file mode 100644 index 0000000000000000000000000000000000000000..360bd4590bc2124249ee241fb7d9d38b92b8fc69 --- /dev/null +++ b/include/log4qt/hierarchy.h @@ -0,0 +1,89 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_HIERARCHY_H +#define LOG4QT_HIERARCHY_H + +#include "loggerrepository.h" + +#include +#include + +namespace Log4Qt +{ + +/*! + * \brief The class Hierarchy implements a logger repository. + * + * \note All the functions declared in this class are thread-safe. + */ +class LOG4QT_EXPORT Hierarchy : public LoggerRepository +{ +public: + Hierarchy(); + ~Hierarchy() override; + +public: + bool exists(const QString &name) const override; + Logger *logger(const QString &name) override; + QList loggers() const override; + Logger *rootLogger() const override; + Level threshold() const override; + void setThreshold(Level level) override; + void setThreshold(const QString &threshold) override; + + bool isDisabled(Level level) override; + void resetConfiguration() override; + void shutdown() override; + +private: + Logger *createLogger(const QString &name); + void resetLogger(Logger *logger, Level level) const; + +private: + mutable QReadWriteLock mObjectGuard; + QHash mLoggers; + Level mThreshold; + Logger *mRootLogger; +}; + +inline Logger *Hierarchy::rootLogger() const +{ + return mRootLogger; +} + +inline Level Hierarchy::threshold() const +{ + return mThreshold; +} + +inline void Hierarchy::setThreshold(Level level) +{ + mThreshold = level; +} + +inline bool Hierarchy::isDisabled(Level level) +{ + return level < mThreshold; +} + +} // namespace Log4Qt + +#endif // LOG4QT_HIERARCHY_H diff --git a/include/log4qt/layout.h b/include/log4qt/layout.h new file mode 100644 index 0000000000000000000000000000000000000000..51a8a7241ee098a246c351e18cf9ce047332d900 --- /dev/null +++ b/include/log4qt/layout.h @@ -0,0 +1,129 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_LAYOUT_H +#define LOG4QT_LAYOUT_H + +#include "log4qt.h" +#include "log4qtsharedptr.h" + +#include + +namespace Log4Qt +{ + +class LoggingEvent; + +/*! + * \brief The class Layout is the base class for all layouts. + * + * \note The ownership and lifetime of objects of this class are managed. See + * \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT Layout : public QObject +{ + Q_OBJECT + + /*! + * The property holds the content type of the layout. + * + * \sa contentType() + */ + Q_PROPERTY(QString footercontentType READ contentType) + /*! + * The property holds the footer used by the layout. + * + * \sa footer(), setFooter() + */ + Q_PROPERTY(QString footer READ footer WRITE setFooter) + /*! + * The property holds the header used by the layout. + * + * \sa header(), setHeader() + */ + Q_PROPERTY(QString header READ header WRITE setHeader) + +public: + Layout(QObject *parent = nullptr); + virtual ~Layout(); + +public: + virtual QString contentType() const; + QString footer() const; + QString header() const; + QString name() const; + void setFooter(const QString &footer); + void setHeader(const QString &header); + void setName(const QString &name); + + virtual void activateOptions(); + virtual QString format(const LoggingEvent &event) = 0; + + /*! + * Returns the end of line seperator for the operating system. + * + * Windows: \\r\\n + * Mac: \\r + * UNIX: \\n + */ + static QString endOfLine(); + + // Member variables +private: + Q_DISABLE_COPY(Layout) + QString mFooter; + QString mHeader; +}; + +inline QString Layout::footer() const +{ + return mFooter; +} + +inline QString Layout::header() const +{ + return mHeader; +} + +inline QString Layout::name() const +{ + return objectName(); +} + +inline void Layout::setFooter(const QString &footer) +{ + mFooter = footer; +} + +inline void Layout::setHeader(const QString &header) +{ + mHeader = header; +} + +inline void Layout::setName(const QString &name) +{ + setObjectName(name); +} + +using LayoutSharedPtr = Log4QtSharedPtr; + +} // namespace Log4Qt + +#endif // LOG4QT_LAYOUT_H diff --git a/include/log4qt/level.h b/include/log4qt/level.h new file mode 100644 index 0000000000000000000000000000000000000000..43e6c350d461046d90efce44fe8fe70440b0438d --- /dev/null +++ b/include/log4qt/level.h @@ -0,0 +1,144 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_LEVEL_H +#define LOG4QT_LEVEL_H + +#include "log4qt.h" + +#include +#include + +namespace Log4Qt +{ + +/*! + * \brief The class Level defines the level of a logging event. + * + * \note All the functions declared in this class are thread-safe. + */ +class LOG4QT_EXPORT Level +{ +public: + // Comparisson operators rely on the order: + // NULL_INT < ALL_INT < TRACE_INT < ... + // Serialisation uses unsigned 8 bit int + + /*! + * The enumeration Value contains all possible Level values. + */ + enum Value + { + /*! NULL_INT is used for no level has been specified */ + NULL_INT = 0, + ALL_INT = 32, + TRACE_INT = 64, + DEBUG_INT = 96, + INFO_INT = 128, + WARN_INT = 150, + ERROR_INT = 182, + FATAL_INT = 214, + OFF_INT = 255 + }; + +public: + Level(Value value = NULL_INT) + : mValue(value) + { + } + + int syslogEquivalent() const; + int toInt() const + { + return mValue; + } + + bool operator==(const Level other) const + { + return mValue == other.mValue; + } + + bool operator!=(const Level other) const + { + return mValue != other.mValue; + } + + bool operator<(const Level other) const + { + return mValue < other.mValue; + } + + bool operator<=(const Level other) const + { + return mValue <= other.mValue; + } + + bool operator>(const Level other) const + { + return mValue > other.mValue; + } + + bool operator>=(const Level other) const + { + return mValue >= other.mValue; + } + QString toString() const; + + static Level fromString(const QString &level, bool *ok = nullptr); + +private: + volatile Value mValue; + +#ifndef QT_NO_DATASTREAM + // Needs to be friend to stream objects + friend LOG4QT_EXPORT QDataStream &operator<<(QDataStream &out, + Log4Qt::Level level); + friend LOG4QT_EXPORT QDataStream &operator>>(QDataStream &in, + Level &level); +#endif // QT_NO_DATASTREAM +}; + +#ifndef QT_NO_DATASTREAM +/*! + * \relates Level + * + * Writes the given error \a rLevel to the given stream \a rStream, + * and returns a reference to the stream. + */ +LOG4QT_EXPORT QDataStream &operator<<(QDataStream &out, + Log4Qt::Level level); + +/*! + * \relates Level + * + * Reads an error from the given stream \a rStream into the given + * error \a rLevel, and returns a reference to the stream. + */ +LOG4QT_EXPORT QDataStream &operator>>(QDataStream &in, + Level &level); +#endif // QT_NO_DATASTREAM + +} // namespace Log4Qt + +Q_DECLARE_METATYPE(Log4Qt::Level) +Q_DECLARE_TYPEINFO(Log4Qt::Level, Q_MOVABLE_TYPE); + + +#endif // LOG4QT_LEVEL_H diff --git a/include/log4qt/log4qt.h b/include/log4qt/log4qt.h new file mode 100644 index 0000000000000000000000000000000000000000..35320d636709d0d4380a3c296fb6ad7b4e4b44c1 --- /dev/null +++ b/include/log4qt/log4qt.h @@ -0,0 +1,558 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_H +#define LOG4QT_H + +#include "log4qtshared.h" + +/*! + * \page Log4Qt/Log4j + * + * %Log4Qt is a C++ port of the Apache Software Foundation Log4j package + * using the Qt Framework. + * + * The documentation describes classes and methods that have been added or + * changed compared to Log4j. + * + * The following sections are describing the implementation in more detail: + * - \ref Changes "Differences to Log4j" + * - \ref Ownership "Object ownership" + * - \ref LogLog "Logging within the package" + * - \ref Init "Initialization procedure" + * - \ref Env "Environment Variables" + * - \ref Undocumented "Undocumented functions" + * - \ref Assumptions "Assumptions" + * + */ + +/*! + * \page Changes Differences to Log4j + * + * The following fundamental differences exist between %Log4Qt and Log4j: + * + * - As a JAVA package Log4j does not have to manage object ownership and + * lifetime in the same way then it is required in C++. For details on + * how object ownership is handled see \ref Ownership "Object ownership". + * - The package uses itself for its internal logging similar to Log4j 1.3. + * For details see \ref LogLog "Logging within the package". + * - The configuration using system properties was replaced with a combination + * of environment variables and application settings. For details see + * \ref Env "Environment Variables". + * - Custom levels are not supported. + * - Multiple Logger Repositories are not supported + * + * The following classes have been changed: + * + * - \ref Log4Qt::AppenderSkeleton "AppenderSkeleton" + * - The procedure of checking, if logging is possible, originally used by + * \ref Log4Qt::WriterAppender "WriterAppender" was generalised and is used + * in \ref Log4Qt::AppenderSkeleton "AppenderSkeleton" and derived classes + * (\ref Log4Qt::AppenderSkeleton::checkEntryConditions() "checkEntryConditions()"). + * - The \ref Log4Qt::AppenderSkeleton::doAppend() "doAppend()" member function will + * check the entry conditions by calling the sub-class specific + * \ref Log4Qt::AppenderSkeleton::checkEntryConditions() "checkEntryConditions()". + * If successful the sub-class specific + * \ref Log4Qt::AppenderSkeleton::append() "append()" function is called. + * + * - Configurator + * - Configure functions return a boolean indicating, if the configuration + * was successful. + * - Configure errors are accessible over + * \ref Log4Qt::ConfiguratorHelper::configureError() + * "ConfiguratorHelper::configureError()". + * - Watching for configuration file changes is a function performed + * centrally by the \ref Log4Qt::ConfiguratorHelper "ConfiguratorHelper". + * The class provides Q_SIGNALS to notify on configuration change and errors. + * - The class \ref Log4Qt::PropertyConfigurator "PropertyConfigurator" was + * extended to be able to read configuration data from a QSettings object. + * + * - \ref Log4Qt::Level "Level" + * - A new value \ref Log4Qt::Level::NULL_INT "Level::NULL_INT" was + * introduced to indicate there is no level set. + * + * - \ref Log4Qt::Logger "Logger" + * - The method \ref Log4Qt::Logger::isEnabledFor() "isEnabledFor()" + * does also take the repository threshold into account. + * - Several overloaded convenience member function are available to log + * messages with arguments of different types. + * - Two macros, \ref Log4Qt::LOG4QT_DECLARE_STATIC_LOGGER "LOG4QT_DECLARE_STATIC_LOGGER" + * and \ref Log4Qt::LOG4QT_DECLARE_QCLASS_LOGGER "LOG4QT_DECLARE_QCLASS_LOGGER", + * allows retrieving and caching of a pointer to a logger object. + * + * - \ref Log4Qt::LogManager "LogManager" + * - A QtMessage handler can be installed via + * \ref Log4Qt::LogManager::setHandleQtMessages() "setHandleQtMessages()", + * to redirect all messages created by calls to qDebug(), qWarning(), + * qCritical() and qFatal() to a logger. The logger is named Qt and can be + * accessed using \ref Log4Qt::LogManager::qtLogger() "qtLogger()". + * - The initialisation procedure is available over a public method + * (\ref Log4Qt::LogManager::startup() "startup()"). + * - The LogManager provides access to the logger used internally by the + * package (\ref Log4Qt::LogManager::logLogger() "logLogger()") and to + * its default initialisation procedure + * (\ref Log4Qt::LogManager::configureLogLogger() "configureLogLogger()"). + * + * - \ref Log4Qt::WriterAppender "WriterAppender" + * - The class will call \ref Log4Qt::WriterAppender::handleIoErrors() + * "handleIoErrors()" after all I/O operations. Sub-classes should + * re-implement the function to handle errors. + * + * - \ref Log4Qt::RollingFileAppender "RollingFileAppender"* + * - The class behaves different to the log4/log4cpp implementation + * on application restart the existing log files are rolled if + * appendFile is set to false to avoid data loss. + * + * The following classes have been added: + * + * - An additional appender class, \ref Log4Qt::DebugAppender "DebugAppender", + * was added. The class appends logging events to the platform specific debug + * output. + * - Various helper class have been introduced: + * - \ref Log4Qt::ClassLogger "ClassLogger": The class ClassLogger provides + * logging for a QObject derived class. + * - \ref Log4Qt::ConfiguratorHelper "ConfiguratorHelper": The class + * ConfiguratorHelper provides a configuration file watch and last error + * for configurator classes. + * - \ref Log4Qt::DateTime "DateTime": The class DateTime provides extended + * functionality for QDateTime. + * - \ref Log4Qt::LogError "LogError": The class LogError represents an error. + * - \ref Log4Qt::Factory "Factory": The class Factory provides factories + * for Appender, Filter and Layout objects. + * - \ref Log4Qt::InitialisationHelper "InitialisationHelper": The class + * InitialisationHelper performs static initialisation tasks. + * - \ref Log4Qt::PatternFormatter "PatternFormatter": The class + * PatternFormatter formats a logging event based on a pattern string. + * - \ref Log4Qt::Properties "Properties": The class Properties implements a + * JAVA property hash. + */ + +/*! + * \page Ownership Object ownership + * + * In difference to the JAVA Log4j package %Log4Qt must manage ownership and + * lifetime of the objects used. This is non trivial as objects are created + * and used in different ways. + * + * In general an object can be created explicitly for example an application + * may create Loggers, Appenders and Layouts during creation of a QApplication + * object. But they can also be automatically created by the package on + * startup using a \ref Log4Qt::PropertyConfigurator "PropertyConfigurator" + * configuration file. Objects may also be created the one way and then used + * the other. Object may be used by multiple other objects. A Layout for example + * may be used by multiple Appenders. Objects are also created from multiple + * threads. The creation may happen during static initialisation and the + * deletion during static de-initialization. + * + * The parent child model used by QObject cannot be used to handle this. It + * cannot automatically delete an object that is used by multiple others as + * for example an Appender used by multiple Loggers. In addition to this + * QObjects and their children must reside in the same thread. This would + * either mean to impose restriction on how objects can be created or to move + * objects to a specific thread. + * + * To allow an automatic deletion of not required objects as Appenders, + * Layouts and Filters QSharedPointer is used + * + * The following example configures a logger and uses reference counting to + * manage the ownership of objects. + * + * \code + * // Create layout + * TTCCLayout *p_layout = new TTCCLayout(); + * + * // Create appender + * ConsoleAppender *p_appender = new ConsoleAppender(p_layout, ConsoleAppender::STDOUT_TARGET); + * p_appender->activateOptions(); + * + * // Get logger + * Logger *p_logger = Logger::logger("MyClass"); + * p_logger->addAppender(p_appender); + * + * // ... + * + * // Remove appender from Logger + * p_logger->removeAllAppenders(); // p_appender and p_layout are deleted here + * \endcode + * + * The following example configures a logger and uses QObject ownership of + * objects. + * + * \code + * QObject *p_parent = new MyObject; + * + * // Create objects + * ConsoleAppender *p_appender = new ConsoleAppender(p_parent); + * TTCCLayout *p_layout = new TTCCLayout(p_appender); + * + * // Configure appender + * p_appender->setTarget(ConsoleAppender::STDOUT_TARGET); + * p_appender->setLayout(LayoutSharedPtr(p_layout)); + * p_appender->activateOptions(); + * + * // Get logger + * Logger *p_logger = Logger::logger("MyClass"); + * p_logger->addAppender(AppenderSharedPtr(p_appender)); + * + * // ... + * + * // Remove appender from Logger + * p_logger->removeAllAppenders(); + * + * delete p_parent; // p_appender and p_layout are deleted here + * \endcode + * + */ + +/*! + * \page LogLog Logging within the package + * + * The package uses itself for logging similar to Log4j 1.3. This brings much + * more flexibility over logging to stdout, stderr like in Log4j 1.2 using + * logLog. It also enables the program to capture and handle errors raised by + * the package. + * + * Using this approach introduces the issue of recursion. The following example + * explains a situation where this happens. Let's say all logger are configured + * to be additive and only the root logger has an appender set. The appender + * is a \ref Log4Qt::FileAppender "FileAppender". During the logging of an + * event an I/O error occurs. The \ref Log4Qt::FileAppender "FileAppender" logs + * an event by itself using the logger %Log4Qt::FileAppender. The event is + * passed to the root logger, which calls then the \ref Log4Qt::FileAppender + * "FileAppender". This causes another I/O error, which is logged by + * the \ref Log4Qt::FileAppender "FileAppender". + * + * To avoid an endless loop the appender will drop the event on a recursive + * invocation. This check is done by \ref Log4Qt::AppenderSkeleton + * "AppenderSkeleton" in \ref Log4Qt::AppenderSkeleton::doAppend() + * "doAppend()". + * + * The problem only occurs, if a logger, appender, layout or filter log an + * event while an event is appended. Neither the logger class nor any of the + * layout or filter classes log events during appending of an event. Most of + * the appender classes may log errors during appending. Only the + * \ref Log4Qt::ListAppender "ListAppender" and + * \ref Log4Qt::ListAppender "ConsoleAppender" are not logging events. + * + * The default configuration uses two \ref Log4Qt::ListAppender + * "ConsoleAppender", one for stderr and one for stdout. No event will be + * dropped, because no recursive invocations can occur. + */ + +/*! + * \page Init Initialization procedure + * + * The package is initialised in two stages. The first stage takes place during + * static initialization. The second stage takes place when the + * \ref Log4Qt::LogManager "LogManager" singleton is created. + * + * During static initialisation the \ref Log4Qt::InitialisationHelper + * "InitialisationHelper" singleton is created . On construction it captures + * the program startup time, reads the required values from the system + * environment and registers the package types with the Qt type system. + * + * The \ref Log4Qt::LogManager "LogManager" singleton is created on first use. + * The creation is usually triggered by the request for a \ref Log4Qt::Logger + * "Logger" object. The call to \ref Log4Qt::Logger::logger() + * "Logger::logger()" is passed through to \ref Log4Qt::LogManager::logger() + * "LogManager::logger()". On creation the \ref Log4Qt::LogManager "LogManager" + * creates a \ref Log4Qt::Hierarchy "Hierarchy" object as logger repository. + * + * After the singleton is created the logging of the package is configured to + * its default by a call to \ref Log4Qt::LogManager::configureLogLogger() + * "LogManager::configureLogLogger()". The logger + * \ref Log4Qt::LogManager::logLogger() "logLogger()" is configured to be not + * additive. Messages with the level \ref Log4Qt::Level::ERROR_INT + * "Level::ERROR_INT" and \ref Log4Qt::Level::FATAL_INT "Level::FATAL_INT" are + * written to \c stderr using a ConsoleAppender. The remaining messages are + * written to \c stdout using a second ConsoleAppender. The level is read from + * the system environment or application settings using + * \ref Log4Qt::InitialisationHelper::setting() + * "InitialisationHelper::setting()" with the key \c Debug. If a level value + * is found, but it is not a valid Level string, + * \ref Log4Qt::Level::DEBUG_INT "Level::DEBUG_INT" is used. If no level string + * is found \ref Log4Qt::Level::ERROR_INT "Level::ERROR_INT" is used. + * + * Once the logging is configured the package is initialised by a call to + * \ref Log4Qt::LogManager::startup() "LogManager::startup()". The function + * will test for the setting \c DefaultInitOverride in the system environment + * and application settings using \ref Log4Qt::InitialisationHelper::setting() + * "InitialisationHelper::setting()". If the value is present and set to + * anything else then \c false, the initialisation is aborted.
+ * The system environment and application settings are tested for the setting + * \c Configuration. If it is found and it is a valid path to a file, the + * package is configured with the file using + * \ref Log4Qt::PropertyConfigurator::doConfigure(const QString &, LoggerRepository *) + * "PropertyConfigurator::doConfigure()". If the setting \c Configuration is + * not available and a QCoreApplication object is present, the application + * settings are tested for a group \c Properties. If the group exists, + * the package is configured with the setting using the + * \ref Log4Qt::PropertyConfigurator::doConfigure(const QSettings &properties, LoggerRepository *) + * "PropertyConfiguratordoConfigure()". If neither a configuration file nor + * configuration settings could be found, the current working directory is + * searched for the file \c "log4qt.properties". If it is found, the package + * is configured with the file using + * \ref Log4Qt::PropertyConfigurator::doConfigure(const QString &, LoggerRepository *) + * "PropertyConfigurator::doConfigure()". + * + * The following example shows how to use application settings to initialise the + * package. + * + * \code + * # file: myapplication.h + * + * #include qapplication.h + * + * class MyApplication : public QApplication + * { + * Q_OBJECT + * + * public: + * MyApplication(); + * ~MyApplication(); + * void setupLog4Qt(); + * } + * \endcode + * \code + * # file: myapplication.cpp + * + * #include myapplication.h + * + * MyApplication::MyApplication( + * { + * // Set Application data to allow Log4Qt initialisation to read the + * // correct values + * setApplicationName("MyApplication"); + * setOrganisationName("MyOrganisation"); + * setOrganizationDomain("www.myorganisation.com"); + * + * // Log first message, which initialises Log4Qt + * Log4Qt::Logger::logger("MyApplication")->info("Hello World"); + * } + * + * MyApplication::~MyApplication() + * { + * } + * + * void MyApplication::setupLog4Qt() + * { + * QSettings s; + * + * // Set logging level for Log4Qt to TRACE + * s.beginGroup("Log4Qt"); + * s.setValue("Debug", "TRACE"); + * + * // Configure logging to log to the file C:/myapp.log using the level TRACE + * s.beginGroup("Properties"); + * s.setValue("log4j.appender.A1", "org.apache.log4j.FileAppender"); + * s.setValue("log4j.appender.A1.file", "C:/myapp.log"); + * s.setValue("log4j.appender.A1.layout", "org.apache.log4j.TTCCLayout"); + * s.setValue("log4j.appender.A1.layout.DateFormat", "ISO8601"); + * s.setValue("log4j.rootLogger", "TRACE, A1"); + * + * // Settings will become active on next application startup + * } + * \endcode + */ + +/*! + * \page Env Environment Variables + * + * The package uses environment variables to control the initialization + * procedure. The environment variables replace the system property entries + * used by Log4j. + * + * For compability reasons the Log4j entry is recognised. Alternatively a + * environment variable style Log4Qt form can be used. The following entries + * are used: + * + * - LOG4QT_DEBUG
+ * The variable controls the \ref Log4Qt::Level "Level" value for the + * logger \ref Log4Qt::LogManager::logLogger() "LogManager::logLogger()". + * If the value is a valid \ref Log4Qt::Level "Level" string, the level for + * the is set to the level. If the value is not a valid + * \ref Log4Qt::Level "Level" string, \ref Log4Qt::Level::DEBUG_INT + * "DEBUG_INT" is used. Otherwise \ref Log4Qt::Level::ERROR_INT "ERROR_INT" + * is used. + * - \ref Log4Qt::LogManager::configureLogLogger() + * "LogManager::configureLogLogger()" + * + * - LOG4QT_DEFAULTINITOVERRIDE
+ * The variable controls the \ref Init "initialization procedure" performed + * by the \ref Log4Qt::LogManager "LogManager" on startup. If it is set to + * any other value then \c false the \ref Init "initialization procedure" + * is skipped. + * - \ref Log4Qt::LogManager::startup() "LogManager::startup()" + * + * - LOG4QT_CONFIGURATION
+ * The variable specifies the configuration file used for initialising the + * package. + * - \ref Log4Qt::LogManager::startup() "LogManager::startup()" + * + * + * Environment variables are read during static initialisation on creation of + * the \ref Log4Qt::InitialisationHelper "InitialisationHelper". They can be + * accessed by calling \ref Log4Qt::InitialisationHelper::environmentSettings() + * "InitialisationHelper::environmentSettings()". + * + * All settings can also be made in the application settings under the group + * \c %Log4Qt. For example the environment variable \c LOG4QT_DEBUG is + * equivalent to the setting \c Debug. If an environment variable is + * set it takes precedence over the application setting. Settings are only + * used, if an QApplication object is available, when the + * \ref Log4Qt::LogManager "LogManager" is + * initialised (see \ref Log4Qt::InitialisationHelper::setting() + * "InitialisationHelper::setting()" for details). + */ + +/*! + * \page Undocumented Undocumented functions + * + * In general it was tried to avoid the usage of undocumented features of Qt. + * Nice to have features like for example Q_DECLARE_PRIVATE are not used. Only + * features that would have been resulted in re-coding the same functionality + * are used. + * + * - QT_WA: The macro is used to call Windows A/W functions + * - \ref Log4Qt::DebugAppender "DebugAppender" + */ + +/*! + * \page Assumptions Assumptions + * + * The following assumptions are used throughout the package: + * + * - Reading / writing of bool or int is thread-safe, if declared volatile + * - \ref Log4Qt::ListAppender "ListAppender" + * - \ref Log4Qt::AppenderSkeleton "AppenderSkeleton" + * - \ref Log4Qt::ConsoleAppender "ConsoleAppender" + * - \ref Log4Qt::FileAppender "FileAppender" + * - \ref Log4Qt::Hierarchy "Hierarchy" + * - \ref Log4Qt::Level "Level" + * - \ref Log4Qt::Logger "Logger" + * - \ref Log4Qt::WriterAppender "WriterAppender" + * - \ref Log4Qt::Layout::format() "Layout::format()" is implemented reentrant + * in all sub-classes. + * - \ref Log4Qt::AppenderSkeleton "AppenderSkeleton" + * - Being able to use singleton objects during static de-initialization without + * order issues is more valuable then their destruction. + * - \ref Log4Qt::LogManager "LogManager" + * - \ref Log4Qt::LOG4QT_IMPLEMENT_INSTANCE "LOG4QT_IMPLEMENT_INSTANCE" + */ + +#include + +#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0) +# error "Log4Qt requires Qt version 5.12.0 or higher" +#endif + +#if (defined(Q_CC_MSVC) && _MSC_VER < 1900) +# error "Log4Qt requires at least msvc version 14 (VS2015) or higher for used c++11 features" +#endif + +#if (!defined(Q_CC_CLANG) && defined(Q_CC_GNU) && Q_CC_GNU < 408) +# error "Log4Qt requires at least gcc version 4.8 or higher for used c++11 features" +#endif + +#if (defined(Q_CC_CLANG) && Q_CC_CLANG < 303) +# error "Log4Qt requires at least clang version 3.3 or higher for used c++11 features" +#endif + + +/* + LOG4QT_VERSION is (major << 16) + (minor << 8) + patch. +*/ +#define LOG4QT_VERSION LOG4QT_VERSION_CHECK(LOG4QT_VERSION_MAJOR, LOG4QT_VERSION_MINOR, LOG4QT_VERSION_PATCH) + +/* + can be used like #if (LOG4QT_VERSION >= LOG4QT_VERSION_CHECK(1, 3, 0)) +*/ +#define LOG4QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch)) + +/*! + * \brief The namespace Log4Qt %Log4Qt encloses all parts of the package. + */ +namespace Log4Qt +{ +/*! + * This macro expands a numeric value of the form 0xMMmmPP (MM = major, + * mm = minor, PP = patch) that specifies Log4Qt's version number. + * This is the version against which the application is compiled. + * + * \sa \ref Log4Qt::LOG4QT_VERSION_STR "LOG4QT_VERSION_STR", + * \ref Log4Qt::LogManager::version() "LogManager::version()" + */ + +/*! + * The macro expands to a string that specifies the Log4Qt's version + * number. This is the version against which the application is compiled. + * + * \sa \ref Log4Qt::LOG4QT_VERSION "LOG4QT_VERSION", + * \ref Log4Qt::LogManager::version() "LogManager::version()" + */ + +enum ErrorCode +{ + OK = 0, + // AppenderSkeleton, FileAppender, WriterAppender + APPENDER_ACTIVATE_MISSING_LAYOUT_ERROR, + APPENDER_ACTIVATE_MISSING_WRITER_ERROR, + APPENDER_ACTIVATE_MISSING_FILE_ERROR, + APPENDER_CLOSED_ERROR, + APPENDER_INVALID_PATTERN_ERROR, + APPENDER_NO_OPEN_FILE_ERROR, + APPENDER_NOT_ACTIVATED_ERROR, + APPENDER_OPENING_FILE_ERROR, + APPENDER_RENAMING_FILE_ERROR, + APPENDER_REMOVE_FILE_ERROR, + APPENDER_USE_INVALID_PATTERN_ERROR, + APPENDER_USE_MISSING_LAYOUT_ERROR, + APPENDER_USE_MISSING_WRITER_ERROR, + APPENDER_WRITING_FILE_ERROR, + // Level + LEVEL_INVALID_LEVEL_STRING, + // Layouts, PatternFormatter + LAYOUT_EXPECTED_DIGIT_ERROR, + LAYOUT_OPTION_IS_NOT_INTEGER_ERROR, + LAYOUT_INTEGER_IS_NOT_POSITIVE_ERROR, + // Logger + LOGGER_INVALID_LEVEL_FOR_ROOT, + // PropertyConfigurator, OptionHandler + CONFIGURATOR_OPENING_FILE_ERROR, + CONFIGURATOR_READING_FILE_ERROR, + CONFIGURATOR_INVALID_SUBSTITUTION_ERROR, + CONFIGURATOR_INVALID_OPTION_ERROR, + CONFIGURATOR_MISSING_APPENDER_ERROR, + CONFIGURATOR_UNKNOWN_APPENDER_CLASS_ERROR, + CONFIGURATOR_MISSING_LAYOUT_ERROR, + CONFIGURATOR_UNKNOWN_LAYOUT_CLASS_ERROR, + CONFIGURATOR_PROPERTY_ERROR, + CONFIGURATOR_UNKNOWN_TYPE_ERROR, + APPENDER_MISSING_DATABASE_OR_TABLE_ERROR, + APPENDER_EXEC_SQL_QUERY_ERROR, + APPENDER_INVALID_DATABASE_LAYOUT_ERROR, + APPENDER_TELNET_SERVER_NOT_RUNNING, + APPENDER_ASNC_DISPATCHER_NOT_RUNNING +}; + +} // namespace Log4Qt + + +#endif // LOG4QT_H diff --git a/include/log4qt/log4qtshared.h b/include/log4qt/log4qtshared.h new file mode 100644 index 0000000000000000000000000000000000000000..370760b491ac7f9435bdf02661010d8679a2344a --- /dev/null +++ b/include/log4qt/log4qtshared.h @@ -0,0 +1,39 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_SHARED_H +#define LOG4QT_SHARED_H + +#include + +// Define LOG4QT_STATIC in you applikation if you want to link against the +// static version of Log4Qt + +#ifdef LOG4QT_STATIC +# define LOG4QT_EXPORT +#else +# if defined(LOG4QT_LIBRARY) +# define LOG4QT_EXPORT Q_DECL_EXPORT +# else +# define LOG4QT_EXPORT Q_DECL_IMPORT +# endif +#endif + +#endif // LOG4QT_SHARED_H diff --git a/include/log4qt/log4qtsharedptr.h b/include/log4qt/log4qtsharedptr.h new file mode 100644 index 0000000000000000000000000000000000000000..2896a8937ea168f796516b43bc2c86066e3ca675 --- /dev/null +++ b/include/log4qt/log4qtsharedptr.h @@ -0,0 +1,60 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_LOG4QTSHAREDPTR_H +#define LOG4QT_LOG4QTSHAREDPTR_H + +#include +#include + +#include + +namespace Log4Qt +{ + +template +class Log4QtSharedPtr : public QSharedPointer +{ +public: + Log4QtSharedPtr(Log4QtClass *ptr) + : QSharedPointer(ptr, &Log4QtClass::deleteLater) + { + static_assert(std::is_base_of::value, "Need a QObject derived class here"); + } + + Log4QtSharedPtr() + : QSharedPointer() + { + } + + Log4QtSharedPtr(const QSharedPointer &other) + : QSharedPointer(other) + { + } + + Log4QtSharedPtr(const QWeakPointer &other) + : QSharedPointer(other) + { + } +}; + +} + +#endif // LOG4QT_LOG4QTSHAREDPTR_H diff --git a/include/log4qt/logger.h b/include/log4qt/logger.h new file mode 100644 index 0000000000000000000000000000000000000000..f8439eb4296fcb2f9e55a8b27ffec6401faa8188 --- /dev/null +++ b/include/log4qt/logger.h @@ -0,0 +1,404 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_LOGGER_H +#define LOG4QT_LOGGER_H + +#include + +#include "helpers/logerror.h" +#include "helpers/classlogger.h" +#include "helpers/appenderattachable.h" +#include "level.h" +#include "logstream.h" +#include "loggingevent.h" + +namespace Log4Qt +{ + +/*! + * LOG4QT_DECLARE_STATIC_LOGGER declares a static function \a FUNCTION that + * returns a pointer to a \ref Log4Qt::Logger "Logger" named after \a CLASS. + * + * On the first invocation the \ref Log4Qt::Logger "Logger" is requested + * by calling \ref Log4Qt::Logger::logger(const char *pName) + * "Logger::logger( #CLASS )". The pointer is stored to be returned on + * subsequent invocations. + * + * The following example shows how to use the macro to define a logger to be + * used within a class not derived from QObject. + * + * \code + * #file: counter.h + * + * #include logger.h + * + * class Counter + * { + * public: + * Counter(); + * Counter(int preset); + * private: + * int mCount; + * } + * \endcode + * \code + * #file: counter.cpp + * + * #include counter.h + * + * LOG4QT_DECLARE_STATIC_LOGGER(logger, Counter) + * + * Counter::Counter() : + * mCount(0) + * {} + * + * void Counter::Counter(int preset) : + * mCount(preset) + * { + * if (preset < 0) + * { + * logger()->warn("Invalid negative counter preset %1. Using 0 instead.", preset); + * mCount = 0; + * } + * } + * \endcode + * + * \note The function created by the macro is thread-safe. + * + * \sa \ref Log4Qt::Logger::logger(const char *pName) "Logger::logger(const char *pName)" + */ +#define LOG4QT_DECLARE_STATIC_LOGGER(FUNCTION, CLASS) \ + static Log4Qt::Logger *FUNCTION() \ + { \ + static Log4Qt::Logger * p_logger(Log4Qt::Logger::logger(#CLASS )); \ + return p_logger; \ + } + +/*! + * LOG4QT_DECLARE_QCLASS_LOGGER declares member functions to retrieve + * \ref Log4Qt::Logger "Logger" for the class it is used in. + * + * On the first invocation the \ref Log4Qt::Logger "Logger" is requested + * by a call to \ref Log4Qt::Logger::logger(const char *pName) + * "Logger::logger(const char *pName)". The pointer is stored to be + * returned on subsequent invocations. + * + * The following example shows how to use the macro to define a logger to be + * used within a class derived from QObject. + * + * \code + * #file: counter.h + * + * #include qobject.h + * #include logger.h + * + * class Counter : public QObject + * { + * Q_OBJECT + * LOG4QT_DECLARE_QCLASS_LOGGER + * public: + * Counter(); + * Counter(int preset); + * private: + * int mCount; + * } + * \endcode + * \code + * #file: counter.cpp + * + * #include counter.h + * + * Counter::Counter() : + * mCount(0) + * {} + * + * void Counter::Counter(int preset) + * mCount(preset) + * { + * if (preset < 0) + * { + * logger()->warn("Invalid negative counter preset %1. Using 0 instead.", preset); + * mCount = 0; + * } + * } + * \endcode + * + * \note The function created by the macro is thread-safe. + * + * \sa \ref Log4Qt::Logger::logger(const char *pName) "Logger::logger(const char *pName)", + * \ref Log4Qt::ClassLogger "ClassLogger" + */ +#define LOG4QT_DECLARE_QCLASS_LOGGER \ + private: \ + mutable Log4Qt::ClassLogger mLog4QtClassLogger; \ + public: \ + inline Log4Qt::Logger *logger() const \ + { return mLog4QtClassLogger.logger(this); } \ + private: + + +class LOG4QT_EXPORT MessageLogger +{ + Q_DISABLE_COPY(MessageLogger) + +public: + explicit MessageLogger(Logger *logger, Level level) : mLogger(logger), mLevel(level) {} + explicit MessageLogger(Logger *logger, Level level, const char *file, int line, const char *function) + : mLogger(logger), mLevel(level), mContext(file, line, function) {} + + void log(const QString &message) const; + template + void log(const QString &message, T &&t, Ts &&...ts) const + { + log(message.arg(std::forward(t)), std::forward(ts)...); + } + LogStream log() const; + +private: + QPointer mLogger; + Level mLevel; + MessageContext mContext; +}; + +// Macros to log with location information, teh logger must have the name +#define l4qFatal(...) \ + for (bool enabled = logger()->isEnabledFor(Log4Qt::Level::FATAL_INT); enabled; enabled = false) \ + Log4Qt::MessageLogger(logger(), Log4Qt::Level::FATAL_INT, __FILE__, __LINE__, Q_FUNC_INFO).log(__VA_ARGS__) +#define l4qError(...) \ + for (bool enabled = logger()->isEnabledFor(Log4Qt::Level::ERROR_INT); enabled; enabled = false) \ + Log4Qt::MessageLogger(logger(), Log4Qt::Level::ERROR_INT, __FILE__, __LINE__, Q_FUNC_INFO).log(__VA_ARGS__) +#define l4qWarn(...) \ + for (bool enabled = logger()->isEnabledFor(Log4Qt::Level::WARN_INT); enabled; enabled = false) \ + Log4Qt::MessageLogger(logger(), Log4Qt::Level::WARN_INT, __FILE__, __LINE__, Q_FUNC_INFO).log(__VA_ARGS__) +#define l4qInfo(...) \ + for (bool enabled = logger()->isEnabledFor(Log4Qt::Level::INFO_INT); enabled; enabled = false) \ + Log4Qt::MessageLogger(logger(), Log4Qt::Level::INFO_INT, __FILE__, __LINE__, Q_FUNC_INFO).log(__VA_ARGS__) +#define l4qDebug(...) \ + for (bool enabled = logger()->isEnabledFor(Log4Qt::Level::DEBUG_INT); enabled; enabled = false) \ + Log4Qt::MessageLogger(logger(), Log4Qt::Level::DEBUG_INT, __FILE__, __LINE__, Q_FUNC_INFO).log(__VA_ARGS__) +#define l4qTrace(...) \ + for (bool enabled = logger()->isEnabledFor(Log4Qt::Level::TRACE_INT); enabled; enabled = false) \ + Log4Qt::MessageLogger(logger(), Log4Qt::Level::TRACE_INT, __FILE__, __LINE__, Q_FUNC_INFO).log(__VA_ARGS__) + +class Appender; +class LoggerRepository; + +/*! + * \brief The class Logger provides logging services. + * + * A pointer to a logger can be retrieved by calling Logger::logger() or + * LogManager::logger() with the class name as argument. Because a logger + * is never destroyed it is possible to store the pointer to the logger. + * This way the lookup of the pointer in the repository is only required + * on the first logging operation. The macros \ref + * Log4Qt::LOG4QT_DECLARE_STATIC_LOGGER "LOG4QT_DECLARE_STATIC_LOGGER" and + * \ref Log4Qt::LOG4QT_DECLARE_QCLASS_LOGGER "LOG4QT_DECLARE_QCLASS_LOGGER" + * provide a thread-safe implementation to store the logger pointer. + * + * \note All the functions declared in this class are thread-safe. + */ +class LOG4QT_EXPORT Logger : public QObject, public AppenderAttachable +{ + Q_OBJECT + + /*! + * The property holds, if the logger is additive. + * + * The default is true for being additive. + * + * \sa additive(), setAdditive() + */ + Q_PROPERTY(bool additivity READ additivity WRITE setAdditivity) + + /*! + * The property holds the level used by the logger. + * + * The default is Level::NULL_INT. + * \sa level(), setLevel() + */ + Q_PROPERTY(Log4Qt::Level level READ level WRITE setLevel) + + /*! + * The property holds the LoggerRepository of the logger. + * + * \sa loggerRepository() + */ + Q_PROPERTY(LoggerRepository *loggerRepository READ loggerRepository) + + /*! + * The property holds the name of the logger. + * + * \sa name() + */ + Q_PROPERTY(QString name READ name) + + /*! + * The property holds the parent logger of the logger. + * + * \sa parentLogger() + */ + Q_PROPERTY(Logger *parentLogger READ parentLogger) + + LOG4QT_DECLARE_QCLASS_LOGGER + +protected: + Logger(LoggerRepository *loggerRepository, Level level, const QString &name, Logger *parent = nullptr); + ~Logger() override; + +private: + Q_DISABLE_COPY(Logger) + +public: + bool additivity() const; + Level level() const; + LoggerRepository *loggerRepository() const; + QString name() const; + Logger *parentLogger() const; + + void setAdditivity(bool additivity); + virtual void setLevel(Level level); + + void callAppenders(const LoggingEvent &event) const; + + Level effectiveLevel() const; + bool isDebugEnabled() const; + + /*! + * Checks if this logger is enabled for a given Level \a level. If the + * logger is enabled the function returns true. Otherwise it returns + * false. + * + * A logger is enabled for a level, if the level is greater or equal + * then the repository threshold and greater and equal then the loggers + * effective level. + * + * \sa LoggerRepository::isDisabled(), effectiveLevel() + */ + bool isEnabledFor(Level level) const; + + bool isErrorEnabled() const; + bool isFatalEnabled() const; + bool isInfoEnabled() const; + bool isTraceEnabled() const; + bool isWarnEnabled() const; + + LogStream debug() const; + void debug(const LogError &logError) const; + void debug(const QString &message) const; + + template + void debug(const QString &message, T &&t, Ts &&...ts) + { + debug(message.arg(std::forward(t)), std::forward(ts)...); + } + + + LogStream error() const; + void error(const LogError &logError) const; + void error(const QString &message) const; + + template + void error(const QString &message, T &&t, Ts &&...ts) + { + error(message.arg(std::forward(t)), std::forward(ts)...); + } + + LogStream fatal() const; + void fatal(const LogError &logError) const; + void fatal(const QString &message) const; + + template + void fatal(const QString &message, T &&t, Ts &&...ts) + { + fatal(message.arg(std::forward(t)), std::forward(ts)...); + } + + LogStream info() const; + void info(const LogError &logError) const; + void info(const QString &message) const; + + template + void info(const QString &message, T &&t, Ts &&...ts) + { + info(message.arg(std::forward(t)), std::forward(ts)...); + } + + LogStream log(Level level) const; + void log(Level level, const LogError &logError) const; + void log(const LoggingEvent &logEvent) const; + + void log(Level level, const QString &message) const; + template + void log(Level level, const QString &message, T &&t, Ts &&...ts) + { + log(level, message.arg(std::forward(t)), std::forward(ts)...); + } + + void logWithLocation(Level level, const char *file, int line, const char *function, const QString &message) const; + template + void logWithLocation(Level level, const char *file, int line, const char *function, const QString &message, T &&t, Ts &&...ts) + { + logWithLocation(level, file, line, function, message.arg(std::forward(t)), std::forward(ts)...); + } + + LogStream trace() const; + void trace(const LogError &logError) const; + void trace(const QString &message) const; + + template + void trace(const QString &message, T &&t, Ts &&...ts) + { + trace(message.arg(std::forward(t)), std::forward(ts)...); + } + + LogStream warn() const; + void warn(const LogError &logError) const; + void warn(const QString &message) const; + + template + void warn(const QString &message, T &&t, Ts &&...ts) + { + warn(message.arg(std::forward(t)), std::forward(ts)...); + } + + // LogManager operations + static Logger *logger(const QString &name); + static Logger *logger(const char *name); + static Logger *rootLogger(); + +protected: + void forcedLog(Level level, const QString &message) const; + void forcedLog(const LoggingEvent &logEvent) const; + +private: + const QString mName; + LoggerRepository *mLoggerRepository; + volatile bool mAdditivity; + Level mLevel; + Logger *mParentLogger; + + // Needs to be friend to create Logger objects + friend class Hierarchy; +}; + +} // namespace Log4Qt + +#endif // LOG4QT_LOGGER_H diff --git a/include/log4qt/loggerrepository.h b/include/log4qt/loggerrepository.h new file mode 100644 index 0000000000000000000000000000000000000000..4a275011c8e1ff2a77a771628b4e74404baf0db8 --- /dev/null +++ b/include/log4qt/loggerrepository.h @@ -0,0 +1,60 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_LOGGERREPOSITORY_H +#define LOG4QT_LOGGERREPOSITORY_H + +#include "level.h" + +#include + +namespace Log4Qt +{ + +class Logger; + +/*! + * \brief The class LoggerRepository is abstract base class for a logger + * repository. + */ +class LOG4QT_EXPORT LoggerRepository +{ +public: + LoggerRepository(); + virtual ~LoggerRepository(); + LoggerRepository(const LoggerRepository &other) = delete; + LoggerRepository &operator=(const LoggerRepository &other) = delete; + + virtual bool exists(const QString &name) const = 0; + virtual Logger *logger(const QString &name) = 0; + virtual QList loggers() const = 0; + virtual Logger *rootLogger() const = 0; + virtual Level threshold() const = 0; + virtual void setThreshold(Level level) = 0; + virtual void setThreshold(const QString &threshold) = 0; + + virtual bool isDisabled(Level level) = 0; + virtual void resetConfiguration() = 0; + virtual void shutdown() = 0; +}; + +} // namespace Log4Qt + +#endif // LOG4QT_LOGGERREPOSITORY_H diff --git a/include/log4qt/loggingevent.h b/include/log4qt/loggingevent.h new file mode 100644 index 0000000000000000000000000000000000000000..480633ff33a71fef7f87856825a6ec1ccb408d90 --- /dev/null +++ b/include/log4qt/loggingevent.h @@ -0,0 +1,244 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_LOG4QTEVENT_H +#define LOG4QT_LOG4QTEVENT_H + +#include "level.h" + +#include +#include +#include + +namespace Log4Qt +{ + +class Logger; + +class MessageContext +{ +public: + explicit MessageContext() + : file(nullptr), line(-1), function(nullptr) {} + explicit MessageContext(const char *fileName, int lineNumber, const char *functionName) + : file(fileName), line(lineNumber), function(functionName) {} + const char *file; + int line; + const char *function; +}; + +/*! + * \brief The class LoggingEvent is the internal representation of a + * logging event. + * + * The class uses milliseconds since 1970-01-01T00:00:00, Coordinated + * Universal Time for time values. For converstion from and to QDateTime + * use DateTime. + */ +class LOG4QT_EXPORT LoggingEvent : public QEvent +{ +public: + static const QEvent::Type eventId; + LoggingEvent(); + virtual ~LoggingEvent(); + + LoggingEvent(const Logger *logger, + Level level, + const QString &message); + LoggingEvent(const Logger *logger, + Level level, + const QString &message, + const MessageContext &context, + const QString &categoryName); + LoggingEvent(const Logger *logger, + Level level, + const QString &message, + qint64 timeStamp); + LoggingEvent(const Logger *logger, + Level level, + const QString &message, + const QString &ndc, + const QHash &properties, + const QString &threadName, + qint64 timeStamp); + LoggingEvent(const Logger *logger, + Level level, + const QString &message, + const QString &ndc, + const QHash &properties, + qint64 timeStamp, + const MessageContext &context, + const QString &categoryName); + LoggingEvent(const Logger *logger, + Level level, + const QString &message, + const QString &ndc, + const QHash &properties, + const QString &threadName, + qint64 timeStamp, + const MessageContext &context, + const QString &categoryName); + + Level level() const; + // LocationInformation locationInformation() const; + const Logger *logger() const; + QString message() const; + QHash mdc() const; + QString ndc() const; + QHash properties() const; + qint64 sequenceNumber() const; + QString threadName() const; + qint64 timeStamp() const; + + QString loggename() const; + QString property(const QString &key) const; + QStringList propertyKeys() const; + void setProperty(const QString &key, const QString &value); + QString toString() const; + static qint64 sequenceCount(); + static qint64 startTime(); + + int lineNumber() const; + void setLineNumber(int lineNumber); + QString fileName() const; + void setFileName(const QString &fileName); + QString functionName() const; + void setMethodName(const QString &functionName); + QString categoryName() const; + void setCategoryName(const QString &categoryName); + MessageContext context() const; + void setContext(const MessageContext &context); + +private: + void setThreadNameToCurrent(); + static qint64 nextSequenceNumber(); + +private: + Level mLevel; + const Logger *mLogger; + QString mMessage; + QString mNdc; + QHash mProperties; + qint64 mSequenceNumber; + QString mThreadName; + qint64 mTimeStamp; + MessageContext mContext; + QString mCategoryName; + + static qint64 msSequenceCount; + +#ifndef QT_NO_DATASTREAM + // Needs to be friend to stream objects + friend LOG4QT_EXPORT QDataStream &operator<<(QDataStream &out, + const LoggingEvent &loggingEvent); + friend LOG4QT_EXPORT QDataStream &operator>>(QDataStream &in, + LoggingEvent &loggingEvent); +#endif // QT_NO_DATASTREAM +}; + +#ifndef QT_NO_DATASTREAM +/*! + * \relates LoggingEvent + * + * Writes the given error \a rLoggingEvent to the given stream \a rStream, + * and returns a reference to the stream. + */ +LOG4QT_EXPORT QDataStream &operator<<(QDataStream &out, + const LoggingEvent &loggingEvent); + +/*! + * \relates LoggingEvent + * + * Reads an error from the given stream \a rStream into the given + * error \a rLoggingEvent, and returns a reference to the stream. + */ +LOG4QT_EXPORT QDataStream &operator>>(QDataStream &in, + LoggingEvent &loggingEvent); +#endif // QT_NO_DATASTREAM + +inline Level LoggingEvent::level() const +{ + return mLevel; +} + +inline const Logger *LoggingEvent::logger() const +{ + return mLogger; +} + +inline QString LoggingEvent::message() const +{ + return mMessage; +} + +inline QHash LoggingEvent::mdc() const +{ + return mProperties; +} + +inline QString LoggingEvent::ndc() const +{ + return mNdc; +} + +inline QHash LoggingEvent::properties() const +{ + return mProperties; +} + +inline qint64 LoggingEvent::sequenceNumber() const +{ + return mSequenceNumber; +} + +inline QString LoggingEvent::threadName() const +{ + return mThreadName; +} + +inline qint64 LoggingEvent::timeStamp() const +{ + return mTimeStamp; +} + +inline QString LoggingEvent::property(const QString &key) const +{ + return mProperties.value(key); +} + +inline QStringList LoggingEvent::propertyKeys() const +{ + return QStringList(mProperties.keys()); +} + +inline void LoggingEvent::setProperty(const QString &key, const QString &value) +{ + mProperties.insert(key, value); +} + + +} // namespace Log4Qt + + +Q_DECLARE_METATYPE(Log4Qt::LoggingEvent) +Q_DECLARE_TYPEINFO(Log4Qt::LoggingEvent, Q_MOVABLE_TYPE); + + +#endif // LOG4QT_LOG4QTEVENT_H diff --git a/include/log4qt/logmanager.h b/include/log4qt/logmanager.h new file mode 100644 index 0000000000000000000000000000000000000000..9f3c00d77950b53c6029ac96a8350822d321f750 --- /dev/null +++ b/include/log4qt/logmanager.h @@ -0,0 +1,373 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_LOGMANAGER_H +#define LOG4QT_LOGMANAGER_H + +#include "level.h" +#include "logger.h" + +#include +#include +#include +#include + +namespace Log4Qt +{ + +class LoggerRepository; + +/*! + * \brief The class LogManager manages Logger in the default + * LoggerRepository. + * + * The LogManager manages logger in a single Hierarchy instance. It + * provides access to special logger over the logLogger(), qtLogger() + * and rootLogger() member functions. + * + * The LogManager is handling the initialisation on startup. The + * initialisation procedure will first attempt to configure the package + * based on environment variables. If the attempt fails it will check for + * the existence of configuration files in several location. For detailed + * description of the initialisation procedure see \ref Init + * "Initialization procedure". + * + * Messages created by qDebug(), qWarning(), qCritical() and qFatal() can + * be can be handled by the LogManager. By default the message handling + * is disabled. It can be enabled by calling setHandleQtMessages(). Once + * enabled all messages are logged using the logger qtLogger(). + * + * The Log4Qt runtime version is accessible over version(). The macros + * \ref Log4Qt::LOG4QT_VERSION "LOG4QT_VERSION" and + * \ref Log4Qt::LOG4QT_VERSION_STR "LOG4QT_VERSION_STR" provide the + * compile time version. + * + * \note All the functions declared in this class are thread-safe. + */ +class LOG4QT_EXPORT LogManager +{ +private: + LogManager(); + ~LogManager(); + Q_DISABLE_COPY(LogManager) + +public: + /*! + * Returns if the handling of messages created by calls to qDebug(), + * qWarning(), qCritical() and qFatal() is activated. + * + * \sa setHandleQtMessages() + */ + static bool handleQtMessages(); + + /*! + * Returns true, if the current properties file is watched with a QFileWatcher + * + * \sa setWatchThisFile() + */ + static bool watchThisFile(); + + /*! + * Returns the filter rules for qc[Info|Debug|Warning|Critical] + * + * \sa setFilterRules() + */ + static QString filterRules(); + + /*! + * Returns the message pattern for qc[Info|Debug|Warning|Critical] + * + * \sa setMessagePattern() + */ + static QString messagePattern(); + + static LoggerRepository *loggerRepository(); + + /*! + * Returns the logger used for logging internal messages. See + * \ref LogLog "Logging within the package" for more details. + * + * Calling this function is equivalent to calling logger("Log4Qt"). + */ + static Logger *logLogger(); + + /*! + * Returns a pointer to the logger used for logging messages created by + * calls to qDebug(), qWarning(), qCritical() and qFatal(). + * + * Calling this function is equivalent to calling logger("Qt"). + * + * \sa setHandleQtMessages() + */ + static Logger *qtLogger(); + + static Logger *rootLogger(); + static QList loggers(); + static Level threshold(); + static void setThreshold(Level level); + + /*! + * Activates or deactivates the handling of messages created by calls + * to qDebug(), qWarning(), qCritical() and qFatal() is activated. + * + * If activated, a Qt message handler is installed. Messages are logged + * using the logger returned by qtLogger(). For fatal messages the same + * exit procedure is implemented as for qFatal(). + * + * The following mappping is used from QtMsgType to Level: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
    QtMsgType     %Level
QtDebugMsg Level::DEBUG_INT
QtWarningMsg Level::WARN_INT
QtCriticalMsg Level::ERROR_INT
QtFatalMsg Level::FATAL_INT
QtSystemMsg Level::TRACE_INT
+ * + * The default value is false for not handling Qt messages. + * + * \sa handleQtMessages(), qInstallMsgHandler(), qFatal() + */ + static void setHandleQtMessages(bool handleQtMessages); + + /*! + * Enables/disables watching of the current properties file + * + * The default value is false for not watching the properties file. + * + * \sa watchThisFile() + */ + static void setWatchThisFile(bool watchThisFile); + + /*! + * Set a message pattern for qc[Debug|Info|Warn|Critical] + * + * \sa messagePattern() + */ + static void setMessagePattern(const QString &pattern); + + /*! + * Set the filter rules for qc[Debug|Info|Warn|Critical] + * + * \sa filterRules() + */ + static void setFilterRules(const QString &rules); + + /*! + * Configures the logging for the package to its default behaviour. + * + * The logger logLogger() is configured to be not additive. Messages + * with the level Level::ERROR_INT and Level::FATAL_INT are written + * to \c stderr using a ConsoleAppender. The remaining messages are + * written to \c stdout using a second ConsoleAppender. The level is + * read from the system environment or application settings using + * InitialisationHelper::setting() with the key \c Debug. If a level + * value is found, but it is not a valid Level string, + * Level::DEBUG_INT is used. If no level string is found + * Level::ERROR_INT is used. + * + * The function does not remove any appender from the logger + * logLogger(). + * + * \sa \ref LogLog "Logging within the package", + * \ref Env "Environment Variables", + * resetConfiguration(), InitialisationHelper::setting() + */ + static void configureLogLogger(); + + static bool exists(const char *pName); + + /*! + * Returns the LogManager instance. + */ + static LogManager *instance(); + + static Logger *logger(const QString &name); + + /*! + * Reset all values contained in logger repository to their default. + * + * All appenders are removed from all loggers. The loggers are handled + * in no particular order. The last loggers to be reset are qtLogger(), + * logLogger() and rootLogger() in that order. + * + * The handling of messages created by calls to qDebug(), qWarning(), + * qCritical() and qFatal() is deactivated. + * + * The internal logging is initialised to its default bahaviour + * using configureLogLogger(). + * + * \sa LoggerRepository::resetConfiguration(), setHandleQtMessages(), + * configureLogLogger() + */ + static void resetConfiguration(); + + static void shutdown(); + + /*! + * Executes the default initialisation procedure of the package. + * + * The function will test for the setting \c DefaultInitOverride in + * the system environment and application settings using + * \ref InitialisationHelper::setting(). If the value is present and + * set to anything else then \c false, the initialisation is aborted. + *
+ * The system environment and application settings are tested for the + * setting \c Configuration. If it is found and it is a valid path to + * a file, the package is configured with the file using + * \ref PropertyConfigurator::doConfigure(const QString &, LoggerRepository *) + * "PropertyConfigurator::doConfigure()". If the setting + * \c Configuration is not available and a QCoreApplication object is + * present, the application settings are tested for a group + * \c Properties. If the group exists, the package is configured + * with the setting using the + * \ref PropertyConfigurator::doConfigure(const QSettings &properties, LoggerRepository *) + * "PropertyConfiguratordoConfigure()". If neither a configuration + * file nor configuration settings could be found, the current working + * directory is searched for the file \c "log4qt.properties". If it is + * found, the package is configured with the file using + * \ref PropertyConfigurator::doConfigure(const QString &, LoggerRepository *) + * "PropertyConfigurator::doConfigure()". + * + * \sa \ref Init "Initialization procedure", + * \ref Env "Environment Variables", + * InitialisationHelper::setting() + */ + static void startup(); + + /*! + * Returns the version number of Log4Qt at run-time. This may be a + * different version than the version the application was compiled + * against. + * + * \sa \ref Log4Qt::LOG4QT_VERSION "LOG4QT_VERSION", + * \ref Log4Qt::LOG4QT_VERSION_STR "LOG4QT_VERSION_STR" + + */ + static const char *version(); + static QVersionNumber versionNumber(); + +private: + void doSetHandleQtMessages(bool handleQtMessages); + void doSetWatchThisFile(bool watchThisFile); + void doSetFilterRules(const QString &filterRules); + void doSetMessagePattern(const QString &messagePattern); + void doConfigureLogLogger(); + void doStartup(); + void welcome(); + + static void qtMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message); + +private: +#if QT_VERSION < 0x050E00 + mutable QMutex mObjectGuard; +#else + mutable QRecursiveMutex mObjectGuard; +#endif + + LoggerRepository *mLoggerRepository; + bool mHandleQtMessages, mWatchThisFile; + QString mFilterRules, mMessagePattern; + QtMessageHandler mQtMsgHandler; + static LogManager *mInstance; +}; + +inline LoggerRepository *LogManager::loggerRepository() +{ + return instance()->mLoggerRepository; +} + +inline bool LogManager::handleQtMessages() +{ + return instance()->mHandleQtMessages; +} + +inline bool LogManager::watchThisFile() +{ + return instance()->mWatchThisFile; +} + +inline QString LogManager::filterRules() +{ + return instance()->mFilterRules; +} + +inline QString LogManager::messagePattern() +{ + return instance()->mMessagePattern; +} + +inline Logger *LogManager::logLogger() +{ + return logger(QStringLiteral("Log4Qt")); +} + +inline Logger *LogManager::qtLogger() +{ + return logger(QStringLiteral("Qt")); +} + +inline void LogManager::setHandleQtMessages(bool handleQtMessages) +{ + instance()->doSetHandleQtMessages(handleQtMessages); +} + +inline void LogManager::setWatchThisFile(bool watchThisFile) +{ + instance()->doSetWatchThisFile(watchThisFile); +} + +inline void LogManager::setFilterRules(const QString &rules) +{ + instance()->doSetFilterRules(rules); +} + +inline void LogManager::setMessagePattern(const QString &pattern) +{ + instance()->doSetMessagePattern(pattern); +} + +inline void LogManager::configureLogLogger() +{ + instance()->doConfigureLogLogger(); +} + +inline void LogManager::startup() +{ + instance()->doStartup(); +} + +} // namespace Log4Qt + +#endif // LOG4QT_LOGMANAGER_H diff --git a/include/log4qt/logstream.h b/include/log4qt/logstream.h new file mode 100644 index 0000000000000000000000000000000000000000..f8c18d41174a4d1148b5f01c8eee8a7eb1cb473d --- /dev/null +++ b/include/log4qt/logstream.h @@ -0,0 +1,61 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_LOGSTREAM_H +#define LOG4QT_LOGSTREAM_H + +#include "level.h" + +#include +#include +#include +#include + +namespace Log4Qt +{ +class Logger; + +class LOG4QT_EXPORT LogStream +{ +public: + LogStream(const Logger &iLogger, Level iLevel); + template + LogStream &operator<<(const T &t) + { + stream->ts << t; + return *this; + } + +private: + struct Stream + { + Stream(const Logger *iLogger, Level iLevel); + ~Stream(); + + QTextStream ts; + QString buffer; + QPointer mLogger; + Level mLevel; + }; + QSharedPointer stream; +}; +} + +#endif // LOG4QT_LOGSTREAM_H diff --git a/include/log4qt/mainthreadappender.h b/include/log4qt/mainthreadappender.h new file mode 100644 index 0000000000000000000000000000000000000000..fe25234ae4d7c9535051ac3e9f88915845a7407b --- /dev/null +++ b/include/log4qt/mainthreadappender.h @@ -0,0 +1,81 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_MAINTHREADAPPENDER_H +#define LOG4QT_MAINTHREADAPPENDER_H + +#include "appenderskeleton.h" +#include "helpers/appenderattachable.h" + +namespace Log4Qt +{ + +/*! + * \brief The class MainThreadAppender uses the QEvent system to write + * log from not main threads within the main thread. + * + * + * \note All the functions declared in this class are thread-safe. + *   + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT MainThreadAppender : public AppenderSkeleton, public AppenderAttachable +{ + Q_OBJECT + +public: + MainThreadAppender(QObject *parent = nullptr); + + bool requiresLayout() const override; + + void activateOptions() override; + + /*! + * Tests if all entry conditions for using append() in this class are + * met. + * + * If a conditions is not met, an error is logged and the function + * returns false. Otherwise the result of + * AppenderSkeleton::checkEntryConditions() is returned. + * + * The checked conditions are: + * - none + * + * The function is called as part of the checkEntryConditions() chain + * started by AppenderSkeleton::doAppend(). + * + * \sa AppenderSkeleton::doAppend(), + * AppenderSkeleton::checkEntryConditions() + */ + bool checkEntryConditions() const override; + +protected: + void append(const LoggingEvent &event) override; + +private: + Q_DISABLE_COPY(MainThreadAppender) + +}; + + +} // namespace Log4Qt + +#endif diff --git a/include/log4qt/mdc.h b/include/log4qt/mdc.h new file mode 100644 index 0000000000000000000000000000000000000000..9b6709adcd528e461d4399003ec870e8538d56fa --- /dev/null +++ b/include/log4qt/mdc.h @@ -0,0 +1,79 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_MDC_H +#define LOG4QT_MDC_H + +#include "log4qt.h" + +#include +#include +#include + +namespace Log4Qt +{ + +/*! + * \brief The class MDC implements a mapped diagnostic context. + * + * \note All the functions declared in this class are thread-safe. + */ +class LOG4QT_EXPORT MDC +{ +private: + MDC(); + Q_DISABLE_COPY(MDC) + +public: + static QString get(const QString &key); + static QHash context(); + + /*! + * Returns the MDC instance. + */ + static MDC *instance(); + + static void put(const QString &key, const QString &value); + static void remove(const QString &key); + +private: + static QHash *localData(); + +private: + QThreadStorage *> mHash; +}; + +inline MDC::MDC() +{} + +inline void MDC::put(const QString &key, const QString &value) +{ + localData()->insert(key, value); +} + +inline void MDC::remove(const QString &key) +{ + localData()->remove(key); +} + + +} // namespace Log4Qt + +#endif // LOG4QT_MDC_H diff --git a/include/log4qt/ndc.h b/include/log4qt/ndc.h new file mode 100644 index 0000000000000000000000000000000000000000..c3252798a50210e9c5987d8853313b2a5f7ab705 --- /dev/null +++ b/include/log4qt/ndc.h @@ -0,0 +1,70 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_NDC_H +#define LOG4QT_NDC_H + +#include "log4qt.h" + +#include +#include +#include + +namespace Log4Qt +{ + +/*! + * \brief The class NDC implements a nested diagnostic context. + * + * The method remove() is not required. QThreadStorage cleans up on thread + * exit. + * + * \note All the functions declared in this class are thread-safe. + */ +class LOG4QT_EXPORT NDC +{ +private: + NDC(); + Q_DISABLE_COPY(NDC) + +public: + static void clear(); + static int depth(); + + /*! + * Returns the NDC instance. + */ + static NDC *instance(); + + static QString pop(); + static void push(const QString &message); + static void setMaxDepth(int maxDepth); + static QString peek(); + +private: + QThreadStorage *> mStack; +}; + +inline NDC::NDC() +{} + +} // namespace Log4Qt + +#endif // LOG4QT_NDC_H diff --git a/include/log4qt/patternlayout.h b/include/log4qt/patternlayout.h new file mode 100644 index 0000000000000000000000000000000000000000..a7488a09436638ceb8552e9abdb8613694866d6d --- /dev/null +++ b/include/log4qt/patternlayout.h @@ -0,0 +1,128 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_PATTERNLAYOUT_H +#define LOG4QT_PATTERNLAYOUT_H + +#include "layout.h" +#include "helpers/patternformatter.h" + +#include + +namespace Log4Qt +{ + +/*! + * \brief The class PatternLayout outputs a logging event based on a + * pattern string. + \li c{section_count} : logger name with optional parameter section_count. Section count from end of logger name, sections delimiter is "::"; + \li d{format_string} : date with optional parameters in "{}"-brackets which used by QDateTime::toString(); + \li m : message + \li p : level name + \li r : relative date/time to start application + \li t : thread name + \li x : ndc name + \li X : mdc name + \li F : file name + \li M : method name + \li L : line number + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT PatternLayout : public Layout +{ + Q_OBJECT + + /*! + * The property holds the conversion pattern used by the appender. + * + * The default is "%m%n". + * + * \sa conversionPattern(), setConversionPattern() + */ + Q_PROPERTY(QString conversionPattern READ conversionPattern WRITE setConversionPattern) + +public: + /*! + * The enum ConversionPattern defines constants for pattern strings. + * + * \sa setConversionPattern(ConversionPattern); + */ + enum ConversionPattern + { + /*! The default conversion pattern string is "%m,%n". */ + DEFAULT_CONVERSION_PATTERN, + /*! + * The ttcc conversion pattern string is + * "%r [%t] %p %c %x - %m%n". + */ + TTCC_CONVERSION_PATTERN + }; + Q_ENUM(ConversionPattern) + + PatternLayout(QObject *parent = nullptr); + PatternLayout(const QString &pattern, + QObject *parent = nullptr); + + /*! + * Creates a PatternLayout with the conversion pattern value specified + * by the \a conversionPattern constant. + */ + PatternLayout(ConversionPattern conversionPattern, + QObject *parent = nullptr); + +private: + Q_DISABLE_COPY(PatternLayout) + +public: + QString conversionPattern() const; + void setConversionPattern(const QString &pattern); + + /*! + * Sets the conversion pattern to the value specified by the + * \a conversionPattern constant. + */ + void setConversionPattern(ConversionPattern conversionPattern); + + QString format(const LoggingEvent &event) override; + +private: + void updatePatternFormatter(); + +private: + QString mPattern; + QScopedPointer mPatternFormatter; +}; + +inline QString PatternLayout::conversionPattern() const +{ + return PatternLayout::mPattern; +} + +inline void PatternLayout::setConversionPattern(const QString &pattern) +{ + mPattern = pattern; + updatePatternFormatter(); +} + +} // namespace Log4Qt + +#endif // LOG4QT_PATTERNLAYOUT_H diff --git a/include/log4qt/propertyconfigurator.h b/include/log4qt/propertyconfigurator.h new file mode 100644 index 0000000000000000000000000000000000000000..7f83e35fc2a1087a2ef71685bea183861907e159 --- /dev/null +++ b/include/log4qt/propertyconfigurator.h @@ -0,0 +1,145 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_PROPERTYCONFIGURATOR_H +#define LOG4QT_PROPERTYCONFIGURATOR_H + +#include "log4qt.h" +#include "layout.h" +#include "appender.h" + +#include + +class QSettings; + +namespace Log4Qt +{ + +class ListAppender; +class Logger; +class Properties; +class LoggerRepository; + +/*! + * \brief The class PropertyConfigurator allows the configuration of the + * package from a JAVA properties file. + * + * \note All the functions declared in this class are thread-safe. + */ +class LOG4QT_EXPORT PropertyConfigurator +{ +public: + PropertyConfigurator(); + +private: + Q_DISABLE_COPY(PropertyConfigurator) + +public: + /*! + * \sa ConfiguratorHelper::configureError() + */ + bool doConfigure(const Properties &properties, + LoggerRepository *loggerRepository = nullptr); + + /*! + * \sa ConfiguratorHelper::configureError() + */ + bool doConfigure(const QString &configFileName, + LoggerRepository *loggerRepository = nullptr); + + /*! + * Reads the configuration data from the QSettings object + * \a settings. + * + * \sa \ref Properties::load(const QSettings &) "Properties::load()", + * ConfiguratorHelper::configureError() + */ + bool doConfigure(const QSettings &settings, + LoggerRepository *loggerRepository = nullptr); + + + /*! + * \sa ConfiguratorHelper::configureError() + */ + static bool configure(const Properties &properties); + + /*! + * \sa ConfiguratorHelper::configureError() + */ + static bool configure(const QString &configFilename); + + /*! + * Reads the configuration data from the QSettings object + * \a settings. + * + * \sa \ref doConfigure(const QSettings &, LoggerRepository *) "doConfigure()", + * \ref Properties::load(const QSettings &) "Properties::load()", + * ConfiguratorHelper::configureError() + */ + static bool configure(const QSettings &settings); + + /*! + * \sa ConfiguratorHelper::configureError(), + * ConfiguratorHelper::configurationFile() + */ + static bool configureAndWatch(const QString &configFilename); + +private: + void configureFromFile(const QString &configFileName, + LoggerRepository *loggerRepository); + void configureFromProperties(const Properties &properties, + LoggerRepository *loggerRepository); + void configureFromSettings(const QSettings &settings, + LoggerRepository *loggerRepository); + void configureGlobalSettings(const Properties &properties, + LoggerRepository *loggerRepository) const; + void configureNonRootElements(const Properties &properties, + LoggerRepository *loggerRepository); + void configureRootLogger(const Properties &properties, + LoggerRepository *loggerRepository); + void parseAdditivityForLogger(const Properties &properties, + Logger *logger, + const QString &log4jName) const; + AppenderSharedPtr parseAppender(const Properties &properties, + const QString &name); + LayoutSharedPtr parseLayout(const Properties &properties, + const QString &appendename); + void parseLogger(const Properties &properties, + Logger *logger, + const QString &key, + const QString &value); + void setProperties(const Properties &properties, + const QString &prefix, + const QStringList &exclusion, + QObject *object); + void startCaptureErrors(); + bool stopCaptureErrors(); + +private: + AppenderSharedPtr mpConfigureErrors; + QHash mAppenderRegistry; +}; + +inline PropertyConfigurator::PropertyConfigurator() +{} + +} // namspace Log4Qt + +#endif // LOG4QT_PROPERTYCONFIGURATOR_H diff --git a/include/log4qt/qmllogger.h b/include/log4qt/qmllogger.h new file mode 100644 index 0000000000000000000000000000000000000000..17be31a69bfef499e42731f28934cd085ea0cd49 --- /dev/null +++ b/include/log4qt/qmllogger.h @@ -0,0 +1,111 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_QMLLOGGER_H +#define LOG4QT_QMLLOGGER_H + +#include "log4qtshared.h" +#include "logger.h" +#include "level.h" + +#include + +namespace Log4Qt +{ + +/*! + * \brief A qml wapper on top of the log4qt logger for passing logger calls from qml to Log4Qt's logger. + * + * Resister qml wrapper: + * \code qmlRegisterType("org.log4qt", 1, 0, "Logger"); \endcode + * + * Use in QML: + * \code + * property Logger logger: Logger {} + * + * Component.onCompleted: { + * logger.trace("Component completed.") + * } + * \endcode + * \note The default logger name is the parents object name. The logger name can also be set: + * property Logger logger: Logger { name: "MyLogger" } + * + * \note The default logger context is Qml. The Logger name is put together from context and name (context.name) + */ +class LOG4QT_EXPORT QmlLogger : public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(QmlLogger) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString context READ context WRITE setContext NOTIFY contextChanged) + Q_PROPERTY(Level level READ level WRITE setLevel NOTIFY levelChanged) + +public: + enum Level + { + Null = Log4Qt::Level::NULL_INT, + All = Log4Qt::Level::ALL_INT, + Trace = Log4Qt::Level::TRACE_INT, + Debug = Log4Qt::Level::DEBUG_INT, + Info = Log4Qt::Level::INFO_INT, + Warn = Log4Qt::Level::WARN_INT, + Error = Log4Qt::Level::ERROR_INT, + Fatal = Log4Qt::Level::FATAL_INT, + Off = Log4Qt::Level::OFF_INT + }; + Q_ENUM(Level) + + explicit QmlLogger(QObject *parent = nullptr); + + // String might be enough as in JavaScript logs concatenation is natural anyway + Q_INVOKABLE void trace(const QString &message) const; + Q_INVOKABLE void debug(const QString &message) const; + Q_INVOKABLE void info(const QString &message) const; + Q_INVOKABLE void error(const QString &message) const; + Q_INVOKABLE void fatal(const QString &message) const; + Q_INVOKABLE void log(QmlLogger::Level level, const QString &message) const; + + QString name() const; + QString context() const; + QmlLogger::Level level() const; + +public Q_SLOTS: + void setName(const QString &name); + void setContext(const QString &context); + void setLevel(QmlLogger::Level level); + +Q_SIGNALS: + void nameChanged(const QString &name); + void contextChanged(const QString &context); + void levelChanged(QmlLogger::Level level); + +private: + QString mContext; + mutable QString mName; + mutable QPointer mLogger; + + QString loggename() const; + Logger *logger() const; +}; + +} + + +#endif // LOG4QT_QMLLOGGER_H diff --git a/include/log4qt/rollingbinaryfileappender.h b/include/log4qt/rollingbinaryfileappender.h new file mode 100644 index 0000000000000000000000000000000000000000..2514e64e3667d601768d6cadd5b75b8f0994c078 --- /dev/null +++ b/include/log4qt/rollingbinaryfileappender.h @@ -0,0 +1,116 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_ROLLINGBINARYFILEAPPENDER_H +#define LOG4QT_ROLLINGBINARYFILEAPPENDER_H + +#include "binaryfileappender.h" + +#include + +namespace Log4Qt +{ + +class RollingBinaryFileAppender : public BinaryFileAppender +{ + Q_OBJECT + Q_PROPERTY(int maxBackupIndex READ maxBackupIndex WRITE setMaxBackupIndex) + Q_PROPERTY(qint64 maximumFileSize READ maximumFileSize WRITE setMaximumFileSize) + Q_PROPERTY(QString datePattern READ datePattern WRITE setDatePattern) +public: + explicit RollingBinaryFileAppender(QObject *parent = nullptr); + + enum DatePattern + { + MINUTELY_ROLLOVER = 0, /*! The minutely date pattern string is "'.'yyyy-MM-dd-hh-mm". */ + HOURLY_ROLLOVER, /*! The hourly date pattern string is "'.'yyyy-MM-dd-hh". */ + HALFDAILY_ROLLOVER, /*! The half-daily date pattern string is "'.'yyyy-MM-dd-a". */ + DAILY_ROLLOVER, /*! The daily date pattern string is "'.'yyyy-MM-dd". */ + WEEKLY_ROLLOVER, /*! The weekly date pattern string is "'.'yyyy-ww". */ + MONTHLY_ROLLOVER /*! The monthly date pattern string is "'.'yyyy-MM". */ + }; + Q_ENUM(DatePattern) + + int maxBackupIndex() const; + void setMaxBackupIndex(int maxBackupIndex); + qint64 maximumFileSize() const; + void setMaximumFileSize(qint64 maximumFileSize); + QString datePattern() const; + void setDatePattern(DatePattern datePattern); + void setDatePattern(const QString &datePattern); + +protected: + void append(const LoggingEvent &event) override; + void activateOptions() override; + + bool checkFotimeRollOver() const; + void rollOvetime(); + bool checkForSizeRollOver() const; + void rollOverSize(); + +private: + void computeFrequency(); + void computeRollOvetime(); + QString frequencyToString() const; + + int mMaxBackupIndex; + qint64 mMaximumFileSize; + + QString mDatePattern; + DatePattern mFrequency; + QString mActiveDatePattern; + QDateTime mRollOvetime; + QString mRollOverSuffix; +}; + + +inline int RollingBinaryFileAppender::maxBackupIndex() const +{ + return mMaxBackupIndex; +} + +inline qint64 RollingBinaryFileAppender::maximumFileSize() const +{ + return mMaximumFileSize; +} + +inline void RollingBinaryFileAppender::setMaxBackupIndex(int maxBackupIndex) +{ + mMaxBackupIndex = maxBackupIndex; +} + +inline void RollingBinaryFileAppender::setMaximumFileSize(qint64 maximumFileSize) +{ + mMaximumFileSize = maximumFileSize; +} + +inline QString RollingBinaryFileAppender::datePattern() const +{ + return mDatePattern; +} + +inline void RollingBinaryFileAppender::setDatePattern(const QString &datePattern) +{ + mDatePattern = datePattern; +} + +} + +#endif // LOG4QT_ROLLINGBINARYFILEAPPENDER_H diff --git a/include/log4qt/rollingfileappender.h b/include/log4qt/rollingfileappender.h new file mode 100644 index 0000000000000000000000000000000000000000..fcdf0df49054d51935bb6e5db93967c1e1c0b461 --- /dev/null +++ b/include/log4qt/rollingfileappender.h @@ -0,0 +1,134 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_ROLINGFILEAPPENDER_H +#define LOG4QT_ROLINGFILEAPPENDER_H + +#include "fileappender.h" + +namespace Log4Qt +{ + +/*! + * \brief The class RollingFileAppender extends FileAppender to backup + * the log files when they reach a certain size. + * On application restart the existing log files are rolled + * if appendFile is set to false to avoid data loss. + * + * \note All the functions declared in this class are thread-safe. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT RollingFileAppender : public FileAppender +{ + Q_OBJECT + + /*! + * The property holds the maximum backup count used by the appender. + * + * The default is 1. + * + * \sa maxBackupIndex(), setMaxBackupIndex() + */ + Q_PROPERTY(int maxBackupIndex READ maxBackupIndex WRITE setMaxBackupIndex) + + /*! + * The property holds the maximum file size used by the appender. + * + * The default is 10 MB (10 * 1024 * 1024). + * + * \sa maximumFileSize(), setMaximumFileSize() + */ + Q_PROPERTY(qint64 maximumFileSize READ maximumFileSize WRITE setMaximumFileSize) + + /*! + * The property sets the maximum file size from a string value. + * + * \sa setMaxFileSize(), maximumFileSize() + */ + Q_PROPERTY(QString maxFileSize READ maxFileSize WRITE setMaxFileSize) + +public: + RollingFileAppender(QObject *parent = nullptr); + RollingFileAppender(const LayoutSharedPtr &layout, + const QString &fileName, + QObject *parent = nullptr); + RollingFileAppender(const LayoutSharedPtr &layout, + const QString &fileName, + bool append, + QObject *parent = nullptr); + +private: + Q_DISABLE_COPY(RollingFileAppender) + +public: + int maxBackupIndex() const; + qint64 maximumFileSize() const; + QString maxFileSize() const; + void setMaxBackupIndex(int maxBackupIndex); + void setMaximumFileSize(qint64 maximumFileSize); + void setMaxFileSize(const QString &maxFileSize); + +protected: + void append(const LoggingEvent &event) override; + void openFile() override; + +private: + void rollOver(); + +private: + int mMaxBackupIndex; + qint64 mMaximumFileSize; +}; + +inline int RollingFileAppender::maxBackupIndex() const +{ + QMutexLocker locker(&mObjectGuard); + return mMaxBackupIndex; +} + +inline qint64 RollingFileAppender::maximumFileSize() const +{ + QMutexLocker locker(&mObjectGuard); + return mMaximumFileSize; +} + +inline QString RollingFileAppender::maxFileSize() const +{ + QMutexLocker locker(&mObjectGuard); + return QString::number(mMaximumFileSize); +} + +inline void RollingFileAppender::setMaxBackupIndex(int maxBackupIndex) +{ + QMutexLocker locker(&mObjectGuard); + mMaxBackupIndex = maxBackupIndex; +} + +inline void RollingFileAppender::setMaximumFileSize(qint64 maximumFileSize) +{ + QMutexLocker locker(&mObjectGuard); + mMaximumFileSize = maximumFileSize; +} + +} // namespace Log4Qt + +#endif // LOG4QT_ROLINGFILEAPPENDER_H diff --git a/include/log4qt/signalappender.h b/include/log4qt/signalappender.h new file mode 100644 index 0000000000000000000000000000000000000000..68de1b53618d1964ab5cf50844ea284edc44282d --- /dev/null +++ b/include/log4qt/signalappender.h @@ -0,0 +1,60 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef SIGNALAPPENDER_H +#define SIGNALAPPENDER_H + +#include "appenderskeleton.h" +#include "loggingevent.h" + +namespace Log4Qt +{ + +/*! + * \ingroup log4qt + * @class SignalAppender signalappender.h "src/kernel/components/signalappender.h" + */ +class LOG4QT_EXPORT SignalAppender : public AppenderSkeleton +{ + Q_OBJECT +public: + explicit SignalAppender(QObject *parent = nullptr); + + bool requiresLayout() const override; + +protected: + void append(const Log4Qt::LoggingEvent &event) override; + +Q_SIGNALS: + /*! + * @param message + */ + void appended(const QString &message); + +}; + +inline bool SignalAppender::requiresLayout() const +{ + return true; +} + +} // namespace Log4Qt + +#endif // SIGNALAPPENDER_H diff --git a/include/log4qt/simplelayout.h b/include/log4qt/simplelayout.h new file mode 100644 index 0000000000000000000000000000000000000000..b97de6a7bc2b21390af013787f1b129a6af9aeed --- /dev/null +++ b/include/log4qt/simplelayout.h @@ -0,0 +1,74 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_SIMPLELAYOUT_H +#define LOG4QT_SIMPLELAYOUT_H + +#include "layout.h" + +namespace Log4Qt +{ + +/*! + * \brief The class SimpleLayout outputs the level and message of a logging + * event. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT SimpleLayout : public Layout +{ + Q_OBJECT + Q_PROPERTY(bool showLevel READ showLevel WRITE setShowLevel) + +public: + SimpleLayout(QObject *parent = nullptr); + +private: + Q_DISABLE_COPY(SimpleLayout) + bool mShowLevel; + +public: + bool showLevel() const; + void setShowLevel(bool show); + + QString format(const LoggingEvent &event) override; + +}; + +inline SimpleLayout::SimpleLayout(QObject *parent) + : Layout(parent) + , mShowLevel{true} +{ +} + +inline bool SimpleLayout::showLevel() const +{ + return mShowLevel; +} + +inline void SimpleLayout::setShowLevel(bool show) +{ + mShowLevel = show; +} + +} // namespace Log4Qt + +#endif // LOG4QT_SIMPLELAYOUT_H diff --git a/include/log4qt/simpletimelayout.h b/include/log4qt/simpletimelayout.h new file mode 100644 index 0000000000000000000000000000000000000000..cf6ea8a3c804cb27f2b363ba1c2d68e9b51d9d85 --- /dev/null +++ b/include/log4qt/simpletimelayout.h @@ -0,0 +1,56 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_SIMPLETIMELAYOUT_H +#define LOG4QT_SIMPLETIMELAYOUT_H + +#include "layout.h" + +namespace Log4Qt +{ + +/*! + * \brief The class SimpleTimeLayout outputs the time, logger name, thread, level and message of a logging + * event. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT SimpleTimeLayout : public Layout +{ + Q_OBJECT + +public: + SimpleTimeLayout(QObject *parent = nullptr); + +private: + Q_DISABLE_COPY(SimpleTimeLayout) + +public: + QString format(const LoggingEvent &event) override; +}; + +inline SimpleTimeLayout::SimpleTimeLayout(QObject *parent) : + Layout(parent) +{} + +} // namespace Log4Qt + +#endif // LOG4QT_SIMPLETIMELAYOUT_H diff --git a/include/log4qt/spi/filter.h b/include/log4qt/spi/filter.h new file mode 100644 index 0000000000000000000000000000000000000000..31dc2b435a48155f7690d172a5c0fc1b195a4eca --- /dev/null +++ b/include/log4qt/spi/filter.h @@ -0,0 +1,83 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_FILTER_H +#define LOG4QT_FILTER_H + +#include "log4qt/log4qt.h" +#include "log4qt/log4qtsharedptr.h" + +#include + +namespace Log4Qt +{ + +class LoggingEvent; +class Filter; + +using FilterSharedPtr = Log4QtSharedPtr; + +/*! + * \brief The class Filter is the base class for all filters. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT Filter : public QObject +{ + Q_OBJECT + + /*! + * The property holds the next filter of this filter. + * + * The default is 0 for no next filter. + * + * \sa next(), setNext() + */ + Q_PROPERTY(FilterSharedPtr next READ next WRITE setNext) + +public: + enum Decision + { + ACCEPT, + DENY, + NEUTRAL + }; + Q_ENUM(Decision) + +public: + Filter(QObject *parent = nullptr); + virtual ~Filter(); + + FilterSharedPtr next() const; + void setNext(const FilterSharedPtr &filter); + + virtual void activateOptions(); + virtual Decision decide(const LoggingEvent &event) const = 0; + +private: + FilterSharedPtr mNext; +}; + + +} // namespace Log4Qt + + +#endif // LOG4QT_FILTER_H diff --git a/include/log4qt/systemlogappender.h b/include/log4qt/systemlogappender.h new file mode 100644 index 0000000000000000000000000000000000000000..da5c85e2216995282e4f728bb76a35589ec98a49 --- /dev/null +++ b/include/log4qt/systemlogappender.h @@ -0,0 +1,73 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef SYSTEMLOGAPPENDER_H +#define SYSTEMLOGAPPENDER_H + +#include "appenderskeleton.h" + +namespace Log4Qt +{ + +/*! + * \brief The class SystemLogAppender appends log events to a Event Log under win* + * and to syslog under *nix. + * + * \note All the functions declared in this class are thread-safe. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT SystemLogAppender: public AppenderSkeleton +{ + Q_OBJECT + + /** + * The property holds the port used by the telenet appender. + * + * The default is QCoreApplication::applicationName() + * + * \sa serviceName(), setServiceName() + */ + Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName) + +public: + explicit SystemLogAppender(QObject *parent = nullptr); + ~SystemLogAppender() override; + + bool requiresLayout() const override; + QString serviceName() const; + void setServiceName(const QString &serviceName); + +protected: + void append(const Log4Qt::LoggingEvent &event) override; + + QString mServiceName; + char *ident; +}; + +inline bool SystemLogAppender::requiresLayout() const +{ + return true; +} + +} + +#endif //#ifndef SYSTEMLOGAPPENDER_H diff --git a/include/log4qt/telnetappender.h b/include/log4qt/telnetappender.h new file mode 100644 index 0000000000000000000000000000000000000000..b39b51e8bac98f34b4ff84780a31c67607a494c8 --- /dev/null +++ b/include/log4qt/telnetappender.h @@ -0,0 +1,188 @@ +/****************************************************************************** + * + * package: Log4Qt + * file: telnetappender.h + * created: July 2010 + * author: Andreas Bacher + * + * + * Copyright 2010 Andreas Bacher + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_TELNETAPPENDER_H +#define LOG4QT_TELNETAPPENDER_H + +#include "appenderskeleton.h" + +#include +#include + +class QTcpServer; +class QTcpSocket; + +namespace Log4Qt +{ + +/*! + * \brief The class TelnetAppender appends log events to a read-only socket (telnet) + *T + * \note All the functions declared in this class are thread-safe. + *   + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT TelnetAppender : public AppenderSkeleton +{ + Q_OBJECT + + /*! + * The property holds the port used by the telenet appender. + * + * The default is 23 for the port. + * + * \sa port, port(), setPort() + */ + Q_PROPERTY(int port READ port WRITE setPort) + + /*! + * The property holds, if the writer flushes after all write operations. + * + * The default is false for flushing. + * + * \sa immediateFlush(), setImmediateFlush() + */ + Q_PROPERTY(bool immediateFlush READ immediateFlush WRITE setImmediateFlush) + + Q_PROPERTY(QHostAddress address READ address WRITE setAddress) + +public: + TelnetAppender(QObject *parent = nullptr); + TelnetAppender(const LayoutSharedPtr &layout, + QObject *parent = nullptr); + TelnetAppender(const LayoutSharedPtr &layout, + const QHostAddress &address, + int port, + QObject *parent = nullptr); + TelnetAppender(const LayoutSharedPtr &layout, + int port, + QObject *parent = nullptr); + ~TelnetAppender() override; + +private: + Q_DISABLE_COPY(TelnetAppender) + +public: + bool requiresLayout() const override; + void activateOptions() override; + void close() override; + + /*! + * Sets the listening port of the telnet server (default = 23) + */ + void setPort(int port); + /*! + * Returns the listening port of the telnet server + */ + int port() const; + /*! + * Set the property immediate flush (default: false) + */ + void setImmediateFlush(bool immediateFlush); + /*! + * Returns immediate flush is enabled + */ + bool immediateFlush() const; + + /*! + * Sets the listenning address of the telnet server (default QHostAddress::Any) + */ + void setAddress(const QHostAddress &address); + /*! + * Returns the listenning address of the telnet server + */ + QHostAddress address() const; + /*! + * Set the welcome message which is send on + */ + void setWelcomeMessage(const QString &welcomeMessage); + +protected: + void append(const LoggingEvent &event) override; + + /*! + * Tests if all entry conditions for using append() in this class are + * met. + * + * If a conditions is not met, an error is logged and the function + * returns false. Otherwise the result of + * AppenderSkeleton::checkEntryConditions() is returned. + * + * The checked conditions are: + * - A writer has been set (APPENDER_USE_MISSING_WRITER_ERROR) + * + * The function is called as part of the checkEntryConditions() chain + * started by AppenderSkeleton::doAppend(). + * + * \sa AppenderSkeleton::doAppend(), + * AppenderSkeleton::checkEntryConditions() + */ + bool checkEntryConditions() const override; + + /*! + * Creates and starts (listening) the TCP server + */ + void openServer(); + /*! + * Stops and destroys the TCP server + */ + void closeServer(); + + QList clients() const; + +private Q_SLOTS: + /*! + * Handles a new incomming connection + */ + void onNewConnection(); + /*! + * Handles a client disconnect + */ + void onClientDisconnected(); + +private: + QHostAddress mAddress; + int mPort; + QTcpServer *mTcpServer; + QList mTcpSockets; + QString mWelcomeMessage; + volatile bool mImmediateFlush; + + void sendWelcomeMessage(QTcpSocket *clientConnection); +}; + +inline bool TelnetAppender::immediateFlush() const +{ + return mImmediateFlush; +} + +inline void TelnetAppender::setImmediateFlush(bool immediateFlush) +{ + mImmediateFlush = immediateFlush; +} + +} // namespace Log4Qt + +#endif // LOG4QT_TELNETAPPENDER_H diff --git a/include/log4qt/ttcclayout.h b/include/log4qt/ttcclayout.h new file mode 100644 index 0000000000000000000000000000000000000000..f8b58210ffe9d83259730b191edf17b682693327 --- /dev/null +++ b/include/log4qt/ttcclayout.h @@ -0,0 +1,205 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_TTCCLAYOUT_H +#define LOG4QT_TTCCLAYOUT_H + +#include "layout.h" +#include "helpers/patternformatter.h" + +#include + +namespace Log4Qt +{ + +class LoggingEvent; + +/*! + * \brief The class TTCCLayout outputs the time, thread, logger and nested + * diagnostic context information of a logging event. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT TTCCLayout : public Layout +{ + Q_OBJECT + + /*! + * The property holds if the logger name is part of the formatted output. + * + * The default value is true for including the logger name. + * + * \sa categoryPrefixing(), setCategoryPrefixing() + */ + Q_PROPERTY(bool categoryPrefixing READ categoryPrefixing WRITE setCategoryPrefixing) + + /*! + * The property holds if the nested context information is part of the + * formatted output. + * + * The default value it true for including the nested context information. + * + * \sa contextPrinting(), setContextPrinting() + */ + Q_PROPERTY(bool contextPrinting READ contextPrinting WRITE setContextPrinting) + + /*! + * The property holds the date format used by the layout. + * + * The default date format is "RELATIVE". + * + * \sa dateFormat(), setDateFormat() + */ + Q_PROPERTY(QString dateFormat READ dateFormat WRITE setDateFormat) + + /*! + * The property holds if the thread name is part of the formatted output. + * + * The default value it true for including the thread name. + * + * \sa threadPrinting(), setThreadPrinting() + */ + Q_PROPERTY(bool threadPrinting READ threadPrinting WRITE setThreadPrinting) + +public: + /*! + * The enum DateFormat defines constants for date formats. + * + * \sa setDateFormat(DateFormat), DateTime::toString() + */ + enum DateFormat + { + /*! The none date format string is "NONE". */ + NONE, + /*! + * The iso8601 date format string is "ISO8601". The date will be + * formatted as yyyy-MM-dd hh:mm:ss.zzz. + */ + ISO8601, + /*! + * The absolute date format string is "ABSOLUTE". The date will be + * formatted as HH:mm:ss.zzz. + */ + ABSOLUTE, + /*! + * The date date format string is "DATE". The date will be formatted + * as MMM YYYY HH:mm:ss.zzz. + */ + DATE, + /*! + * The relative date format string is "RELATIVE". The date will be + * formatted as milliseconds since start of the program. + */ + RELATIVE + }; + Q_ENUM(DateFormat) + + TTCCLayout(QObject *parent = nullptr); + TTCCLayout(const QString &dateFormat, + QObject *parent = nullptr); + + /*! + * Creates a TTCCLayout with the date formar value specified by + * the \a dateFormat constant and the parent \a parent. + */ + TTCCLayout(DateFormat dateFormat, + QObject *parent = nullptr); + +private: + Q_DISABLE_COPY(TTCCLayout) + +public: + bool categoryPrefixing() const; + bool contextPrinting() const; + QString dateFormat() const; + bool threadPrinting() const; + void setCategoryPrefixing(bool categoryPrefixing); + void setContextPrinting(bool contextPrinting); + void setDateFormat(const QString &dateFormat); + + /*! + * Sets the date format to the value specified by the \a dateFormat + * constant. + */ + void setDateFormat(DateFormat dateFormat); + + void setThreadPrinting(bool threadPrinting); + virtual QString format(const LoggingEvent &event) override; + +private: + void updatePatternFormatter(); + +private: + bool mCategoryPrefixing; + bool mContextPrinting; + QString mDateFormat; + bool mThreadPrinting; + QScopedPointer mPatternFormatter; +}; + +inline bool TTCCLayout::categoryPrefixing() const +{ + return mCategoryPrefixing; +} + +inline bool TTCCLayout::contextPrinting() const +{ + return mContextPrinting; +} + +inline QString TTCCLayout::dateFormat() const +{ + return mDateFormat; +} + +inline bool TTCCLayout::threadPrinting() const +{ + return mThreadPrinting; +} + +inline void TTCCLayout::setCategoryPrefixing(bool categoryPrefixing) +{ + mCategoryPrefixing = categoryPrefixing; + updatePatternFormatter(); +} + +inline void TTCCLayout::setContextPrinting(bool contextPrinting) +{ + mContextPrinting = contextPrinting; + updatePatternFormatter(); +} + +inline void TTCCLayout::setDateFormat(const QString &dateFormat) +{ + mDateFormat = dateFormat; + updatePatternFormatter(); +} + +inline void TTCCLayout::setThreadPrinting(bool threadPrinting) +{ + mThreadPrinting = threadPrinting; + updatePatternFormatter(); +} + + +} // namespace Log4Qt + +#endif // LOG4QT_TTCCLAYOUT_H diff --git a/include/log4qt/varia/binaryeventfilter.h b/include/log4qt/varia/binaryeventfilter.h new file mode 100644 index 0000000000000000000000000000000000000000..7fdd86c46822563d1a228245a1a39fd1095e4b9f --- /dev/null +++ b/include/log4qt/varia/binaryeventfilter.h @@ -0,0 +1,57 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_BINARYEVENTFILTER_H +#define LOG4QT_BINARYEVENTFILTER_H + +#include "log4qt/spi/filter.h" + +namespace Log4Qt +{ + +class LOG4QT_EXPORT BinaryEventFilter : public Filter +{ + Q_OBJECT + Q_PROPERTY(bool acceptBinaryEvents READ acceptBinaryEvents WRITE setAcceptBinaryEvents) +public: + explicit BinaryEventFilter(QObject *parent = nullptr); + + bool acceptBinaryEvents() const; + void setAcceptBinaryEvents(bool accept); + + Decision decide(const LoggingEvent &event) const override; + +private: + bool mAcceptBinaryEvents; +}; + +inline bool BinaryEventFilter::acceptBinaryEvents() const +{ + return mAcceptBinaryEvents; +} + +inline void BinaryEventFilter::setAcceptBinaryEvents(bool accept) +{ + mAcceptBinaryEvents = accept; +} + +} // namespace Log4Qt + +#endif // LOG4QT_BINARYEVENTFILTER_H diff --git a/include/log4qt/varia/debugappender.h b/include/log4qt/varia/debugappender.h new file mode 100644 index 0000000000000000000000000000000000000000..5d72060f239cb89266358dac5efbc0976854b9cc --- /dev/null +++ b/include/log4qt/varia/debugappender.h @@ -0,0 +1,90 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_DEBUGAPPENDER_H +#define LOG4QT_DEBUGAPPENDER_H + +#include "log4qt/appenderskeleton.h" + +namespace Log4Qt +{ + +/*! + * \brief The class DebugAppender appends logging events to the platform + * specific debug output. + * + * A DebugAppender appends to the Debugger on Windows and to stderr on all + * other systems. + * + * \note All the functions declared in this class are thread-safe. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT DebugAppender : public AppenderSkeleton +{ + Q_OBJECT + +public: + /*! + * Creates a DebugAppender. + */ + DebugAppender(QObject *parent = nullptr); + + /*! + * Creates a DebugAppender with the specified layout \a pLayout + */ + DebugAppender(const LayoutSharedPtr &layout, + QObject *parent = nullptr); + +private: + Q_DISABLE_COPY(DebugAppender) + +public: + /*! + * The DebugAppended requires a layout. The function returns true. + * + * \sa setLayout() + */ + bool requiresLayout() const override; + +protected: + /*! + * Appends the specified logging event \a event to the debug output. + * The output is formatted using the appender's layout. + * + * The method is called by the AppenderSkeleton::doAppend() after it + * the entry conditions have been tested and it has been found that the + * logging event needs to be appended. + * + * \sa setLayout(), AppenderSkeleton::doAppend(), checkEntryConditions() + */ + void append(const LoggingEvent &event) override; + +}; + +inline DebugAppender::DebugAppender(QObject *parent) : + AppenderSkeleton(parent) +{} + + +} // namespace Log4Qt + +#endif // LOG4QT_DEBUGAPPENDER_H diff --git a/include/log4qt/varia/denyallfilter.h b/include/log4qt/varia/denyallfilter.h new file mode 100644 index 0000000000000000000000000000000000000000..47c93a204b110ccde49a1685a07062a9a989a16f --- /dev/null +++ b/include/log4qt/varia/denyallfilter.h @@ -0,0 +1,51 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_DENYALLFILTER_H +#define LOG4QT_DENYALLFILTER_H + +#include "log4qt/spi/filter.h" + +namespace Log4Qt +{ + +/*! + * \brief The class DenyAllFilter drops all logging events + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT DenyAllFilter : public Filter +{ + Q_OBJECT + +public: + DenyAllFilter(QObject *parent = nullptr); + + Decision decide(const LoggingEvent &event) const override + { + Q_UNUSED(&event); + return Filter::DENY; + } +}; + +} // namespace Log4Qt + +#endif // LOG4QT_DENYALLFILTER_H diff --git a/include/log4qt/varia/levelmatchfilter.h b/include/log4qt/varia/levelmatchfilter.h new file mode 100644 index 0000000000000000000000000000000000000000..21f54c0222159b14fcc3bf617fd5cfed810f23db --- /dev/null +++ b/include/log4qt/varia/levelmatchfilter.h @@ -0,0 +1,96 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_LEVELMATCHFILTER_H +#define LOG4QT_LEVELMATCHFILTER_H + +#include "log4qt/spi/filter.h" +#include "log4qt/level.h" + +namespace Log4Qt +{ + +/*! + * \brief The class LevelMatchFilter allows logging events with a specified + * level. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT LevelMatchFilter : public Filter +{ + Q_OBJECT + + /*! + * The property holds if an event is accpeted on a match. + * + * The default is true. + * + * \sa acceptOnMatch(), setAcceptOnMatch() + */ + Q_PROPERTY(bool acceptOnMatch READ acceptOnMatch WRITE setAcceptOnMatch) + + /*! + * The property holds the level to match for this filter. + * + * The default is Level::NULL_INT. + * + * \sa levelToMatch(), setLevelToMatch() + */ + Q_PROPERTY(Log4Qt::Level levelToMatch READ levelToMatch WRITE setLevelToMatch) + +public: + LevelMatchFilter(QObject *parent = nullptr); + + bool acceptOnMatch() const; + Level levelToMatch() const; + void setAcceptOnMatch(bool accept); + void setLevelToMatch(Level level); + + Decision decide(const LoggingEvent &event) const override; + +private: + bool mAcceptOnMatch; + Level mLevelToMatch; +}; + +inline bool LevelMatchFilter::acceptOnMatch() const +{ + return mAcceptOnMatch; +} + +inline Level LevelMatchFilter::levelToMatch() const +{ + return mLevelToMatch; +} + +inline void LevelMatchFilter::setAcceptOnMatch(bool accept) +{ + mAcceptOnMatch = accept; +} + +inline void LevelMatchFilter::setLevelToMatch(Level level) +{ + mLevelToMatch = level; +} + +} // namespace Log4Qt + +#endif // LOG4QT_LEVELMATCHFILTER_H diff --git a/include/log4qt/varia/levelrangefilter.h b/include/log4qt/varia/levelrangefilter.h new file mode 100644 index 0000000000000000000000000000000000000000..e55b7a1a80fe9148c58c250b62385a818a62ec3a --- /dev/null +++ b/include/log4qt/varia/levelrangefilter.h @@ -0,0 +1,118 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_LEVELRANGEFILTER_H +#define LOG4QT_LEVELRANGEFILTER_H + +#include "log4qt/spi/filter.h" +#include "log4qt/level.h" + +namespace Log4Qt +{ + +/*! + * \brief The class LevelMatchFilter allows logging events with levels in a + * specified range. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT LevelRangeFilter : public Filter +{ + Q_OBJECT + + /*! + * The property holds if an event is accpeted on a match. + * + * The default is true. + * + * \sa acceptOnMatch(), acceptOnMatch() + */ + Q_PROPERTY(bool acceptOnMatch READ acceptOnMatch WRITE setAcceptOnMatch) + + /*! + * The property holds the maximum level of the range for this filter. + * + * The default is Level::OFF_INT. + * + * \sa levelMax(), setLevelMax() + */ + Q_PROPERTY(Log4Qt::Level levelMax READ levelMax WRITE setLevelMax) + + /*! + * The property holds the minimum level of the range for this filter. + * + * The default is Level::NULL_INT. + * + * \sa levelMin(), setLevelMin() + */ + Q_PROPERTY(Log4Qt::Level levelMin READ levelMin WRITE setLevelMin) + +public: + LevelRangeFilter(QObject *parent = nullptr); + + bool acceptOnMatch() const; + Level levelMax() const; + Level levelMin() const; + void setAcceptOnMatch(bool accept); + void setLevelMax(Level level); + void setLevelMin(Level level); + + Decision decide(const LoggingEvent &event) const override; + +private: + bool mAcceptOnMatch; + Level mLevelMin; + Level mLevelMax; +}; + +inline bool LevelRangeFilter::acceptOnMatch() const +{ + return mAcceptOnMatch; +} + +inline Level LevelRangeFilter::levelMax() const +{ + return mLevelMax; +} + +inline Level LevelRangeFilter::levelMin() const +{ + return mLevelMin; +} + +inline void LevelRangeFilter::setAcceptOnMatch(bool accept) +{ + mAcceptOnMatch = accept; +} + +inline void LevelRangeFilter::setLevelMax(Level level) +{ + mLevelMax = level; +} + +inline void LevelRangeFilter::setLevelMin(Level level) +{ + mLevelMin = level; +} + +} // namespace Log4Qt + +#endif // LOG4QT_LEVELRANGEFILTER_H diff --git a/include/log4qt/varia/listappender.h b/include/log4qt/varia/listappender.h new file mode 100644 index 0000000000000000000000000000000000000000..a8851b448a9747c484309811c79073db86d5f904 --- /dev/null +++ b/include/log4qt/varia/listappender.h @@ -0,0 +1,132 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_LISTAPPENDER_H +#define LOG4QT_LISTAPPENDER_H + +#include "log4qt/appenderskeleton.h" +#include "log4qt/loggingevent.h" + +#include + +namespace Log4Qt +{ + +/*! + * \brief The class ListAppender appends logging events to a list for later + * processing. + * + * \note All the functions declared in this class are thread-safe. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT ListAppender : public AppenderSkeleton +{ + Q_OBJECT + + /*! + * The property holds, if the Appender is used by a configurator. + * + * The default value is false for not being a configurator list. + * + * \sa configuratorList(), setConfiguratorList() + */ + Q_PROPERTY(bool configuratorList READ configuratorList WRITE setConfiguratorList) + + /*! + * The property holds the maximum count used by the appender. + * + * The default maximum count is -1 for unlimited. + * + * \sa maxCount(), setMaxCount() + */ + Q_PROPERTY(int maxCount READ maxCount WRITE setMaxCount) + +public: + ListAppender(QObject *parent = nullptr); + +public: + /*! + * Returns true, if the appender is used by a configurator. Otherweise it returns + * false. + * + * \sa setConfiguratorList() + */ + bool configuratorList() const; + + QList list() const; + int maxCount() const; + + /*! + * Sets that the appender is used by a configurator. If set to true, the appender + * will not be removed from a Logger when Logger::removeAllAppenders()is called. + * This way the appender can collect events raised during the configuration process. + * + * \sa configuratorList(), BasicConfigurator, PropertyConfigurator, + * ConfiguratorHelper::configureError() + */ + void setConfiguratorList(bool isConfiguratorList); + + void setMaxCount(int n); + + QList clearList(); + bool requiresLayout() const override; + +protected: + void append(const LoggingEvent &event) override; + + /*! + * Ensures that the count of events is less or equal then the maxium + * count. If the list contains too many items, items are deleted from + * the begin of the list. + */ + void ensureMaxCount(); + +private: + Q_DISABLE_COPY(ListAppender) + volatile bool mConfiguratorList; + QList mList; + volatile int mMaxCount; +}; + +inline bool ListAppender::configuratorList() const +{ + return mConfiguratorList; +} + +inline int ListAppender::maxCount() const +{ + return mMaxCount; +} + +inline void ListAppender::setConfiguratorList(bool isConfiguratorList) +{ + mConfiguratorList = isConfiguratorList; +} + +inline bool ListAppender::requiresLayout() const +{ + return false; +} + +} // namespace Log4Qt + +#endif // LOG4QT_LISTAPPENDER_H diff --git a/include/log4qt/varia/nullappender.h b/include/log4qt/varia/nullappender.h new file mode 100644 index 0000000000000000000000000000000000000000..8c337bb63f9322f48e82deb4aa818e9f5d1cb5c4 --- /dev/null +++ b/include/log4qt/varia/nullappender.h @@ -0,0 +1,62 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_NULLAPPENDER_H +#define LOG4QT_NULLAPPENDER_H + +#include "log4qt/appenderskeleton.h" + +namespace Log4Qt +{ + +/*! + * \brief The class NullAppender ignores all requests to append. + * + * \note All the functions declared in this class are thread-safe. + * + * \note The ownership and lifetime of objects of this class are managed. See + * \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT NullAppender : public AppenderSkeleton +{ + Q_OBJECT + +public: + NullAppender(QObject *parent = nullptr); + ~NullAppender() override; + +public: + bool requiresLayout() const override; + +protected: + void append(const LoggingEvent &event) override; + +private: + Q_DISABLE_COPY(NullAppender) +}; + +inline bool NullAppender::requiresLayout() const +{ + return false; +} + +} // namespace Log4Qt + +#endif // LOG4QT_NULLAPPENDER_H diff --git a/include/log4qt/varia/stringmatchfilter.h b/include/log4qt/varia/stringmatchfilter.h new file mode 100644 index 0000000000000000000000000000000000000000..761e8d472b5ea9f8b382b4d1762e00727c9c2355 --- /dev/null +++ b/include/log4qt/varia/stringmatchfilter.h @@ -0,0 +1,93 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_STRINGMATCHFILTER_H +#define LOG4QT_STRINGMATCHFILTER_H + +#include "log4qt/spi/filter.h" + +namespace Log4Qt +{ + +/*! + * \brief The class StringMatchFilter allows logging events with a + * specified level. + * + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT StringMatchFilter : public Filter +{ + Q_OBJECT + + /*! + * The property holds if an event is accpeted on a match. + * + * The default is true. + * + * \sa acceptOnMatch(), acceptOnMatch() + */ + Q_PROPERTY(bool acceptOnMatch READ acceptOnMatch WRITE setAcceptOnMatch) + + /*! + * The property holds the string to match for this filter. + * + * \sa stringToMatch(), setStringToMatch() + */ + Q_PROPERTY(QString stringToMatch READ stringToMatch WRITE setStringToMatch) + +public: + StringMatchFilter(QObject *parent = nullptr); + + bool acceptOnMatch() const; + QString stringToMatch() const; + void setAcceptOnMatch(bool accept); + void setStringToMatch(const QString &string); + + Decision decide(const LoggingEvent &event) const override; + +private: + bool mAcceptOnMatch; + QString mStringToMatch; +}; + +inline bool StringMatchFilter::acceptOnMatch() const +{ + return mAcceptOnMatch; +} + +inline QString StringMatchFilter::stringToMatch() const +{ + return mStringToMatch; +} + +inline void StringMatchFilter::setAcceptOnMatch(bool accept) +{ + mAcceptOnMatch = accept; +} + +inline void StringMatchFilter::setStringToMatch(const QString &string) +{ + mStringToMatch = string; +} + +} // namespace Log4Qt + +#endif // LOG4QT_STRINGMATCHFILTER_H diff --git a/include/log4qt/writerappender.h b/include/log4qt/writerappender.h new file mode 100644 index 0000000000000000000000000000000000000000..73e7b89064494ccc247d8bc7431d74fecb985824 --- /dev/null +++ b/include/log4qt/writerappender.h @@ -0,0 +1,193 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_WRITERAPPENDER_H +#define LOG4QT_WRITERAPPENDER_H + +#include "appenderskeleton.h" + +#if QT_VERSION >= 0x060000 +#include +#endif + +#if QT_VERSION < 0x060000 +class QTextCodec; +#endif + +class QTextStream; + +namespace Log4Qt +{ + +/*! + * \brief The class WriterAppender appends log events to a QTextStream. + * + * \note All the functions declared in this class are thread-safe. + *   + * \note The ownership and lifetime of objects of this class are managed. + * See \ref Ownership "Object ownership" for more details. + */ +class LOG4QT_EXPORT WriterAppender : public AppenderSkeleton +{ + Q_OBJECT + + /*! + * The property holds the codec the appender uses. + * + * The default is null to use the codec the writer has set. + * + * \sa encoding(), setEncoding() + */ +#if QT_VERSION < 0x060000 + Q_PROPERTY(QTextCodec *encoding READ encoding WRITE setEncoding) +#else + Q_PROPERTY(QStringConverter::Encoding encoding READ encoding WRITE setEncoding) +#endif + + /*! + * The property holds the writer the appender uses. + * + * \sa writer(), setWriter() + */ + Q_PROPERTY(QTextStream *writer READ writer WRITE setWriter) + + /*! + * The property holds, if the writer flushes after all write operations. + * + * The default is true for flushing. + * + * \sa immediateFlush(), setImmediateFlush() + */ + Q_PROPERTY(bool immediateFlush READ immediateFlush WRITE setImmediateFlush) + +public: + WriterAppender(QObject *parent = nullptr); + WriterAppender(const LayoutSharedPtr &layout, + QObject *parent = nullptr); + WriterAppender(const LayoutSharedPtr &layout, + QTextStream *textStream, + QObject *parent = nullptr); + ~WriterAppender() override; + +private: + Q_DISABLE_COPY(WriterAppender) + +public: + bool requiresLayout() const override; +#if QT_VERSION < 0x060000 + QTextCodec *encoding() const; +#else + QStringConverter::Encoding encoding() const; +#endif + bool immediateFlush() const; + QTextStream *writer() const; + + /*! + * Sets the codec used by the writer to \a pTextCoded. + * + * If a codec is set with setEncoding, it will overwrite the codec set + * in the text stream. A subsequent call with \a pTextCoded equals null + * will resets the codec to the default QTextCodec::codecForLocale(). + * + * \sa encoding(), QTextSream::setCodec(), QTextCodec::codecForLocale() + */ +#if QT_VERSION < 0x060000 + void setEncoding(QTextCodec *encoding); +#else + void setEncoding(QStringConverter::Encoding encoding); +#endif + void setImmediateFlush(bool immediateFlush); + void setWriter(QTextStream *textStream); + + void activateOptions() override; + void close() override; + +protected: + void append(const LoggingEvent &event) override; + + /*! + * Tests if all entry conditions for using append() in this class are + * met. + * + * If a conditions is not met, an error is logged and the function + * returns false. Otherwise the result of + * AppenderSkeleton::checkEntryConditions() is returned. + * + * The checked conditions are: + * - A writer has been set (APPENDER_USE_MISSING_WRITER_ERROR) + * + * The function is called as part of the checkEntryConditions() chain + * started by AppenderSkeleton::doAppend(). + * + * \sa AppenderSkeleton::doAppend(), + * AppenderSkeleton::checkEntryConditions() + */ + bool checkEntryConditions() const override; + + void closeWriter(); + + virtual bool handleIoErrors() const; + void writeFooter() const; + void writeHeader() const; + +private: +#if QT_VERSION < 0x060000 + QTextCodec *mEncoding; +#else + QStringConverter::Encoding mEncoding; +#endif + QTextStream *mWriter; + volatile bool mImmediateFlush; + void closeInternal(); +}; + +#if QT_VERSION < 0x060000 +inline QTextCodec *WriterAppender::encoding() const +{ + QMutexLocker locker(&mObjectGuard); + return mEncoding; +} +#else +inline QStringConverter::Encoding WriterAppender::encoding() const +{ + QMutexLocker locker(&mObjectGuard); + return mEncoding; +} +#endif + +inline bool WriterAppender::immediateFlush() const +{ + return mImmediateFlush; +} + +inline QTextStream *WriterAppender::writer() const +{ + return mWriter; +} + +inline void WriterAppender::setImmediateFlush(bool immediateFlush) +{ + mImmediateFlush = immediateFlush; +} + + +} // namespace Log4Qt + +#endif // LOG4QT_WRITERAPPENDER_H diff --git a/include/log4qt/xmllayout.h b/include/log4qt/xmllayout.h new file mode 100644 index 0000000000000000000000000000000000000000..f2226f2093f5a604fa0efc4a4b251ec855a1c2d5 --- /dev/null +++ b/include/log4qt/xmllayout.h @@ -0,0 +1,44 @@ +/****************************************************************************** + * + * This file is part of Log4Qt library. + * + * Copyright (C) 2007 - 2020 Log4Qt contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef LOG4QT_XMLLAYOUT_H +#define LOG4QT_XMLLAYOUT_H + +#include "layout.h" + +namespace Log4Qt +{ + +class LOG4QT_EXPORT XMLLayout : public Layout +{ + Q_OBJECT +public: + explicit XMLLayout(QObject *parent = nullptr); + + QString format(const LoggingEvent &event) override; + +private: + Q_DISABLE_COPY(XMLLayout) +}; + +} + +#endif // LOG4QT_XMLLAYOUT_H + diff --git a/lib/log4qt/liblog4qt.so b/lib/log4qt/liblog4qt.so new file mode 120000 index 0000000000000000000000000000000000000000..8018e4defad0af3cb9d2723ffc59240756314638 --- /dev/null +++ b/lib/log4qt/liblog4qt.so @@ -0,0 +1 @@ +liblog4qt.so.1.0.0 \ No newline at end of file diff --git a/lib/log4qt/liblog4qt.so.1 b/lib/log4qt/liblog4qt.so.1 new file mode 120000 index 0000000000000000000000000000000000000000..8018e4defad0af3cb9d2723ffc59240756314638 --- /dev/null +++ b/lib/log4qt/liblog4qt.so.1 @@ -0,0 +1 @@ +liblog4qt.so.1.0.0 \ No newline at end of file diff --git a/lib/log4qt/liblog4qt.so.1.0 b/lib/log4qt/liblog4qt.so.1.0 new file mode 120000 index 0000000000000000000000000000000000000000..8018e4defad0af3cb9d2723ffc59240756314638 --- /dev/null +++ b/lib/log4qt/liblog4qt.so.1.0 @@ -0,0 +1 @@ +liblog4qt.so.1.0.0 \ No newline at end of file diff --git a/lib/log4qt/liblog4qt.so.1.0.0 b/lib/log4qt/liblog4qt.so.1.0.0 new file mode 100755 index 0000000000000000000000000000000000000000..d3bc3819392277178e91382ac7436da6f1c2b2ef Binary files /dev/null and b/lib/log4qt/liblog4qt.so.1.0.0 differ diff --git a/rms.pro b/rms.pro index df74a5e52b5c8037369c43f44cfa76b8a553c444..8da5a1f06bb4a7e363b2377351f8d4d719cf04c4 100644 --- a/rms.pro +++ b/rms.pro @@ -3,105 +3,36 @@ # Project created by QtCreator 2016-07-14T07:09:29 # #------------------------------------------------- -include(config.pri) +include(src/rms/config.pri) QT += core gui QT += sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +PROJECT_ROOT = $$PWD + +APP_TARGET = rms TARGET = $${APP_TARGET} TEMPLATE = app +DESTDIR = $$PROJECT_ROOT/bin + +BUILD_DIST = $$PROJECT_ROOT/build +MOC_DIR = $${BUILD_DIST}/moc +OBJECTS_DIR = $${BUILD_DIST}/obj +RCC_DIR = $${BUILD_DIST}/rcc +UI_DIR = $${BUILD_DIST}/ui -DESTDIR = $${BUILD_DIST} -MOC_DIR = $${PROJECT_ROOT}/compile/moc -OBJECTS_DIR = $${PROJECT_ROOT}/compile/obj -RCC_DIR = $${PROJECT_ROOT}/compile/rcc -UI_DIR = $${PROJECT_ROOT}/compile/ui +# 引入动态库 +LIBS += -L$${PROJECT_ROOT}/lib/sqlite3 -lqsqlite \ + -L$${PROJECT_ROOT}/lib/log4qt -llog4qt -LIBS += -L$${PROJECT_ROOT}/lib/sqlite3 -lqsqlite +# 引入头文件目录 +INCLUDEPATH += $${PROJECT_ROOT}/include \ + $${PROJECT_ROOT}/src/rms/include RESOURCES += \ res.qrc CONFIG += c++17 -HEADERS += \ - src/include/main/mainwindow.h \ - src/include/dialog/dayincomequery_dialog.h \ - src/include/dialog/add_reduce_dialog.h \ - src/include/dialog/staffregister_dialog.h \ - src/include/dialog/varietymenu_dialog.h \ - src/include/dialog/dishescount_dialog.h \ - src/include/dialog/foodinfo_dialog.h \ - src/include/dialog/login_dialog.h \ - src/include/dialog/monthincomequery_dialog.h \ - src/include/dialog/selectseat_dialog.h \ - src/include/dialog/stockqquery_dialog.h \ - src/include/dialog/check_out_dialog.h \ - src/include/dialog/orderdishes_dialog.h \ - src/include/ui/ui_stockquery_dialog.h \ - src/include/ui/ui_mainwindow.h \ - src/include/ui/ui_foodinfo_dialog.h \ - src/include/ui/ui_add_reduce_dialog.h \ - src/include/ui/ui_orderdishes_dialog.h \ - src/include/ui/ui_monthincomequery_dialog.h \ - src/include/ui/ui_selectseat_dialog.h \ - src/include/ui/ui_staffregister_dialog.h \ - src/include/ui/ui_login_dialog.h \ - src/include/ui/ui_check_out_dialog.h \ - src/include/ui/ui_dayincomequery_dialog.h \ - src/include/ui/ui_dishescount_dialog.h \ - src/include/ui/ui_varietymenu_dialog.h \ - src/include/db/day_statistics.h \ - src/include/db/manage_databese.h\ - src/include/db/order_dishes.h \ - src/include/db/search_sales.h \ - src/include/db/food_info.h \ - src/include/db/user_management.h \ - src/include/db/seat_info.h \ - src/include/db/check.h \ - src/include/db/create_table.h \ - src/include/db/excute_sql_file.h \ - src/include/db/init_database.h - -SOURCES += \ - src/sources/main/main.cpp \ - src/sources/main/mainwindow.cpp \ - src/sources/dialog/selectseat_dialog.cpp \ - src/sources/dialog/login_dialog.cpp \ - src/sources/dialog/varietymenu_dialog.cpp \ - src/sources/dialog/stockqquery_dialog.cpp \ - src/sources/dialog/foodinfo_dialog.cpp \ - src/sources/dialog/add_reduce_dialog.cpp \ - src/sources/dialog/dayincomequery_dialog.cpp \ - src/sources/dialog/check_out_dialog.cpp \ - src/sources/dialog/orderdishes_dialog.cpp \ - src/sources/dialog/dishescount_dialog.cpp \ - src/sources/dialog/staffregister_dialog.cpp \ - src/sources/dialog/monthincomequery_dialog.cpp \ - src/sources/ui/ui_dishescount_dialog.cpp \ - src/sources/ui/ui_staffregister_dialog.cpp \ - src/sources/ui/ui_selectseat_dialog.cpp \ - src/sources/ui/ui_add_reduce_dialog.cpp \ - src/sources/ui/ui_dayincomequery_dialog.cpp \ - src/sources/ui/ui_login_dialog.cpp \ - src/sources/ui/ui_mainwindow.cpp \ - src/sources/ui/ui_varietymenu_dialog.cpp \ - src/sources/ui/ui_check_out_dialog.cpp \ - src/sources/ui/ui_monthincomequery_dialog.cpp \ - src/sources/ui/ui_orderdishes_dialog.cpp \ - src/sources/ui/ui_foodinfo_dialog.cpp \ - src/sources/ui/ui_stockquery_dialog.cpp \ - src/sources/db/day_statistics.cpp \ - src/sources/db/manage_databese.cpp \ - src/sources/db/order_dishes.cpp \ - src/sources/db/search_sales.cpp \ - src/sources/db/food_info.cpp \ - src/sources/db/user_management.cpp \ - src/sources/db/seat_info.cpp \ - src/sources/db/check.cpp \ - src/sources/db/excute_sql_file.cpp \ - src/sources/db/create_table.cpp \ - src/sources/db/init_database.cpp - diff --git a/src/include/dialog/add_reduce_dialog.h b/src/include/dialog/add_reduce_dialog.h deleted file mode 100644 index 0bb85fd795077bcdf7fc7bc063499b13b2549db5..0000000000000000000000000000000000000000 --- a/src/include/dialog/add_reduce_dialog.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef ADD_REDUCE_DIALOG_H -#define ADD_REDUCE_DIALOG_H - -#include -#include -#include -#include - -#include "src/include/db/order_dishes.h" -#include "src/include/db/food_info.h" - -namespace Ui { -class Add_Reduce_Dialog; -} - -class Add_Reduce_Dialog : public QDialog -{ - Q_OBJECT - -public: - explicit Add_Reduce_Dialog(QWidget *parent = 0); - ~Add_Reduce_Dialog(); - -private slots: - void on_okButton_clicked(); - - void on_cancelButton_clicked(); - - void on_addButton_clicked(); - - void on_deleteButton_clicked(); - -// void on_comboBox_currentIndexChanged(const QString &arg1); - - void on_comboBox_activated(const QString &arg1); - -private: - Ui::Add_Reduce_Dialog *ui; - int count; - void initFoodTable(); - void initCombox(); - - void initWindowFoodTable(); - void initWindowIsAddTable(); - - OrderDishes *dishes; - -}; - -#endif // ADD_REDUCE_DIALOG_H diff --git a/src/include/dialog/check_out_dialog.h b/src/include/dialog/check_out_dialog.h deleted file mode 100644 index f92dc480baf966b758d6333e22555c3269bbacf5..0000000000000000000000000000000000000000 --- a/src/include/dialog/check_out_dialog.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef CHECK_OUTDIALOG_H -#define CHECK_OUTDIALOG_H - -#include -#include - -#include "src/include/db/seat_info.h" -#include "src/include/db/check.h" - -namespace Ui { -class Check_OutDialog; -} - -class Check_OutDialog : public QDialog -{ - Q_OBJECT - -public: - explicit Check_OutDialog(QWidget *parent = 0); - ~Check_OutDialog(); - - void initWindow(); - -private slots: - void on_pushButton_clicked(); - - void on_pushButton_2_clicked(); - - void on_comboBox_activated(const QString &arg1); - - void on_receipts_lineEdit_textEdited(const QString &arg1); - -private: - Ui::Check_OutDialog *ui; - void initCombox(); - SeatInfo *seat; -}; - -#endif // CHECK_OUTDIALOG_H diff --git a/src/include/dialog/dayincomequery_dialog.h b/src/include/dialog/dayincomequery_dialog.h deleted file mode 100644 index 97a066a42e9f3f169967029b3b801a7dc1076590..0000000000000000000000000000000000000000 --- a/src/include/dialog/dayincomequery_dialog.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef DAYINCOMEQUERY_DIALOG_H -#define DAYINCOMEQUERY_DIALOG_H - -#include -#include -#include -#include - -#include "src/include/db/search_sales.h" -namespace Ui { -class DayIncomeQuery_Dialog; -} - -class DayIncomeQuery_Dialog : public QDialog -{ - Q_OBJECT - -public: - explicit DayIncomeQuery_Dialog(QWidget *parent = 0); - ~DayIncomeQuery_Dialog(); - - void initCombox(); - -private slots: - void on_queryButton_clicked(); - - void on_quitButton_clicked(); - -private: - Ui::DayIncomeQuery_Dialog *ui; -}; - -#endif // DAYINCOMEQUERY_DIALOG_H diff --git a/src/include/dialog/foodinfo_dialog.h b/src/include/dialog/foodinfo_dialog.h deleted file mode 100644 index 218869cae16005f7b9558b32dfa39a19ee91c5de..0000000000000000000000000000000000000000 --- a/src/include/dialog/foodinfo_dialog.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef FOODINFO_DIALOG_H -#define FOODINFO_DIALOG_H - -#include -#include - -#include - -#include "src/include/db/food_info.h" - -namespace Ui { -class FoodInfo_Dialog; -} - -class FoodInfo_Dialog : public QDialog -{ - Q_OBJECT - -public: - explicit FoodInfo_Dialog(QWidget *parent = 0); - ~FoodInfo_Dialog(); - -private slots: - void on_deleteFood_Button_clicked(); - - void on_addFood_Button_clicked(); - -private: - Ui::FoodInfo_Dialog *ui; - - void initFood(); - - FoodInfo *foodInfo; -}; - -#endif // FOODINFO_DIALOG_H diff --git a/src/include/dialog/monthincomequery_dialog.h b/src/include/dialog/monthincomequery_dialog.h deleted file mode 100644 index 1fadd4c5068d87bbac3cda21ba5c5b1944222f40..0000000000000000000000000000000000000000 --- a/src/include/dialog/monthincomequery_dialog.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef MONTHINCOMEQUERY_DIALOG_H -#define MONTHINCOMEQUERY_DIALOG_H - -#include -#include -#include -#include - -#include "src/include/db/search_sales.h" - -namespace Ui { -class MonthIncomeQuery_Dialog; -} - -class MonthIncomeQuery_Dialog : public QDialog -{ - Q_OBJECT - -public: - explicit MonthIncomeQuery_Dialog(QWidget *parent = 0); - ~MonthIncomeQuery_Dialog(); - - void initCombox(); - -private slots: - void on_queryButton_clicked(); - - void on_quitButton_clicked(); - -private: - Ui::MonthIncomeQuery_Dialog *ui; - QSqlDatabase m_db; -}; - -#endif // MONTHINCOMEQUERY_DIALOG_H diff --git a/src/include/dialog/orderdishes_dialog.h b/src/include/dialog/orderdishes_dialog.h deleted file mode 100644 index bec8e78329b417742c0c278a572122fc0d9eca89..0000000000000000000000000000000000000000 --- a/src/include/dialog/orderdishes_dialog.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef ORDERDISHESDIALOG_H -#define ORDERDISHESDIALOG_H - -#include -#include -#include -#include -#include -#include - -#include "src/include/db/food_info.h" -#include "src/include/db/order_dishes.h" - -namespace Ui { -class OrderDishesDialog; -} - -class OrderDishesDialog : public QDialog -{ - Q_OBJECT - -public: - explicit OrderDishesDialog(QWidget *parent = 0); - ~OrderDishesDialog(); - - void receiverIdData(QString data); - QString returnTime(); - bool returnIsOrder(); - void initFoodTable(); - - -private slots: - void on_OkButton_clicked(); - void on_cancelButton_clicked(); - void on_deleteButton_clicked(); - void on_addButton_clicked(); - -private: - Ui::OrderDishesDialog *ui; - QString idData; - int count; - QString dateStr; - //初始化菜单表 - bool isOrder; - - //窗口初始化 - void initWindow(); -}; - -#endif // ORDERDISHESDIALOG_H diff --git a/src/include/dialog/staffregister_dialog.h b/src/include/dialog/staffregister_dialog.h deleted file mode 100644 index 2af1052143ecee10c675d2211bf84a8cc3aa050a..0000000000000000000000000000000000000000 --- a/src/include/dialog/staffregister_dialog.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef STAFFREGISTER_DIALOG_H -#define STAFFREGISTER_DIALOG_H - -#include -#include -#include -#include - -#include "src/include/db/user_management.h" - -namespace Ui { -class staffRegister_Dialog; -} - -class staffRegister_Dialog : public QDialog -{ - Q_OBJECT - -public: - explicit staffRegister_Dialog(QWidget *parent = 0); - ~staffRegister_Dialog(); - -private slots: - void on_pushButton_clicked(); - - void on_pushButton_2_clicked(); - - void on_cancel_pushButton_clicked(); - -private: - Ui::staffRegister_Dialog *ui; - -}; - -#endif // STAFFREGISTER_DIALOG_H diff --git a/src/include/main/mainwindow.h b/src/include/main/mainwindow.h deleted file mode 100644 index e37a26bf2569808162e4c3480a1bf61871264b77..0000000000000000000000000000000000000000 --- a/src/include/main/mainwindow.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include "src/include/dialog/login_dialog.h" -#include -#include - -namespace Ui { -class MainWindow; -} - -class MainWindow : public QMainWindow { - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - - void setEnabledMenu(bool e); //启用菜单 - -private slots: - void on_action_Login_triggered(); //系统登录触发器 - - void on_action_Quit_triggered(); //系统退出触发器 - - void on_action_Start_triggered(); //开始点菜触发器 - - void on_action_AddorReduce_triggered(); //加菜减菜触发器 - - void on_action_CustomerSettlement_triggered(); //顾客结账触发器 - - void on_action_DaySettlement_triggered(); //当日结算触发器 - - void on_action_UserRegistered_triggered(); //员工注册触发器 - - void on_action_DayIncomeQuery_triggered(); //日收入查询触发器 - - void on_action_MonthIncomeQuery_triggered(); //月收入查询触发器 - - void on_action_PurchaseQuery_triggered(); //进货查询触发器 - - void on_action_MenuInfo_triggered(); //菜单信息触发器 - -private: - Ui::MainWindow *ui; - - bool admin; //用户名 - bool pass; //密码 -}; - -#endif // MAINWINDOW_H diff --git a/src/rms/config.pri b/src/rms/config.pri new file mode 100644 index 0000000000000000000000000000000000000000..f3404b005afda2108522a10e38fa108b0fff7f34 --- /dev/null +++ b/src/rms/config.pri @@ -0,0 +1,78 @@ +HEADERS += \ + $$PWD/include/main/mainwindow.h \ + $$PWD/include/dialog/dayincomequery_dialog.h \ + $$PWD/include/dialog/add_reduce_dialog.h \ + $$PWD/include/dialog/staffregister_dialog.h \ + $$PWD/include/dialog/varietymenu_dialog.h \ + $$PWD/include/dialog/dishescount_dialog.h \ + $$PWD/include/dialog/foodinfo_dialog.h \ + $$PWD/include/dialog/login_dialog.h \ + $$PWD/include/dialog/monthincomequery_dialog.h \ + $$PWD/include/dialog/selectseat_dialog.h \ + $$PWD/include/dialog/stockqquery_dialog.h \ + $$PWD/include/dialog/check_out_dialog.h \ + $$PWD/include/dialog/orderdishes_dialog.h \ + $$PWD/include/ui/ui_stockquery_dialog.h \ + $$PWD/include/ui/ui_mainwindow.h \ + $$PWD/include/ui/ui_foodinfo_dialog.h \ + $$PWD/include/ui/ui_add_reduce_dialog.h \ + $$PWD/include/ui/ui_orderdishes_dialog.h \ + $$PWD/include/ui/ui_monthincomequery_dialog.h \ + $$PWD/include/ui/ui_selectseat_dialog.h \ + $$PWD/include/ui/ui_staffregister_dialog.h \ + $$PWD/include/ui/ui_login_dialog.h \ + $$PWD/include/ui/ui_check_out_dialog.h \ + $$PWD/include/ui/ui_dayincomequery_dialog.h \ + $$PWD/include/ui/ui_dishescount_dialog.h \ + $$PWD/include/ui/ui_varietymenu_dialog.h \ + $$PWD/include/db/day_statistics.h \ + $$PWD/include/db/manage_databese.h\ + $$PWD/include/db/order_dishes.h \ + $$PWD/include/db/search_sales.h \ + $$PWD/include/db/food_info.h \ + $$PWD/include/db/user_management.h \ + $$PWD/include/db/seat_info.h \ + $$PWD/include/db/check.h \ + $$PWD/include/db/create_table.h \ + $$PWD/include/db/excute_sql_file.h \ + $$PWD/include/db/init_database.h + +SOURCES += \ + $$PWD/sources/main/main.cpp \ + $$PWD/sources/main/mainwindow.cpp \ + $$PWD/sources/dialog/selectseat_dialog.cpp \ + $$PWD/sources/dialog/login_dialog.cpp \ + $$PWD/sources/dialog/varietymenu_dialog.cpp \ + $$PWD/sources/dialog/stockqquery_dialog.cpp \ + $$PWD/sources/dialog/foodinfo_dialog.cpp \ + $$PWD/sources/dialog/add_reduce_dialog.cpp \ + $$PWD/sources/dialog/dayincomequery_dialog.cpp \ + $$PWD/sources/dialog/check_out_dialog.cpp \ + $$PWD/sources/dialog/orderdishes_dialog.cpp \ + $$PWD/sources/dialog/dishescount_dialog.cpp \ + $$PWD/sources/dialog/staffregister_dialog.cpp \ + $$PWD/sources/dialog/monthincomequery_dialog.cpp \ + $$PWD/sources/ui/ui_dishescount_dialog.cpp \ + $$PWD/sources/ui/ui_staffregister_dialog.cpp \ + $$PWD/sources/ui/ui_selectseat_dialog.cpp \ + $$PWD/sources/ui/ui_add_reduce_dialog.cpp \ + $$PWD/sources/ui/ui_dayincomequery_dialog.cpp \ + $$PWD/sources/ui/ui_login_dialog.cpp \ + $$PWD/sources/ui/ui_mainwindow.cpp \ + $$PWD/sources/ui/ui_varietymenu_dialog.cpp \ + $$PWD/sources/ui/ui_check_out_dialog.cpp \ + $$PWD/sources/ui/ui_monthincomequery_dialog.cpp \ + $$PWD/sources/ui/ui_orderdishes_dialog.cpp \ + $$PWD/sources/ui/ui_foodinfo_dialog.cpp \ + $$PWD/sources/ui/ui_stockquery_dialog.cpp \ + $$PWD/sources/db/day_statistics.cpp \ + $$PWD/sources/db/manage_databese.cpp \ + $$PWD/sources/db/order_dishes.cpp \ + $$PWD/sources/db/search_sales.cpp \ + $$PWD/sources/db/food_info.cpp \ + $$PWD/sources/db/user_management.cpp \ + $$PWD/sources/db/seat_info.cpp \ + $$PWD/sources/db/check.cpp \ + $$PWD/sources/db/excute_sql_file.cpp \ + $$PWD/sources/db/create_table.cpp \ + $$PWD/sources/db/init_database.cpp diff --git a/src/include/db/check.h b/src/rms/include/db/check.h similarity index 100% rename from src/include/db/check.h rename to src/rms/include/db/check.h diff --git a/src/include/db/create_table.h b/src/rms/include/db/create_table.h similarity index 100% rename from src/include/db/create_table.h rename to src/rms/include/db/create_table.h diff --git a/src/include/db/day_statistics.h b/src/rms/include/db/day_statistics.h similarity index 100% rename from src/include/db/day_statistics.h rename to src/rms/include/db/day_statistics.h diff --git a/src/include/db/excute_sql_file.h b/src/rms/include/db/excute_sql_file.h similarity index 100% rename from src/include/db/excute_sql_file.h rename to src/rms/include/db/excute_sql_file.h diff --git a/src/include/db/food_info.h b/src/rms/include/db/food_info.h similarity index 100% rename from src/include/db/food_info.h rename to src/rms/include/db/food_info.h diff --git a/src/include/db/init_database.h b/src/rms/include/db/init_database.h similarity index 100% rename from src/include/db/init_database.h rename to src/rms/include/db/init_database.h diff --git a/src/include/db/manage_databese.h b/src/rms/include/db/manage_databese.h similarity index 100% rename from src/include/db/manage_databese.h rename to src/rms/include/db/manage_databese.h diff --git a/src/include/db/order_dishes.h b/src/rms/include/db/order_dishes.h similarity index 100% rename from src/include/db/order_dishes.h rename to src/rms/include/db/order_dishes.h diff --git a/src/include/db/search_sales.h b/src/rms/include/db/search_sales.h similarity index 100% rename from src/include/db/search_sales.h rename to src/rms/include/db/search_sales.h diff --git a/src/include/db/seat_info.h b/src/rms/include/db/seat_info.h similarity index 100% rename from src/include/db/seat_info.h rename to src/rms/include/db/seat_info.h diff --git a/src/include/db/user_management.h b/src/rms/include/db/user_management.h similarity index 100% rename from src/include/db/user_management.h rename to src/rms/include/db/user_management.h diff --git a/src/rms/include/dialog/add_reduce_dialog.h b/src/rms/include/dialog/add_reduce_dialog.h new file mode 100644 index 0000000000000000000000000000000000000000..f85bab1b91013a959ee04012c35a033d795324a4 --- /dev/null +++ b/src/rms/include/dialog/add_reduce_dialog.h @@ -0,0 +1,47 @@ +#ifndef ADD_REDUCE_DIALOG_H +#define ADD_REDUCE_DIALOG_H + +#include +#include +#include +#include + +#include "db/order_dishes.h" + +namespace Ui { +class Add_Reduce_Dialog; +} + +class Add_Reduce_Dialog : public QDialog { + Q_OBJECT + + public: + explicit Add_Reduce_Dialog(QWidget *parent = 0); + ~Add_Reduce_Dialog(); + + private slots: + void on_okButton_clicked(); + + void on_cancelButton_clicked(); + + void on_addButton_clicked(); + + void on_deleteButton_clicked(); + + // void on_comboBox_currentIndexChanged(const QString &arg1); + + void on_comboBox_activated(const QString &arg1); + + private: + Ui::Add_Reduce_Dialog *ui; + int count; + void initFoodTable(); + void initCombox(); + + void initWindowFoodTable(); + void initWindowIsAddTable(); + + OrderDishes *dishes; +}; + +#endif // ADD_REDUCE_DIALOG_H diff --git a/src/rms/include/dialog/check_out_dialog.h b/src/rms/include/dialog/check_out_dialog.h new file mode 100644 index 0000000000000000000000000000000000000000..5cf4a6a64238749e4727c5d4583b24470cf78d1c --- /dev/null +++ b/src/rms/include/dialog/check_out_dialog.h @@ -0,0 +1,37 @@ +#ifndef CHECK_OUTDIALOG_H +#define CHECK_OUTDIALOG_H + +#include +#include +#include +#include "db/seat_info.h" + +namespace Ui { +class Check_OutDialog; +} + +class Check_OutDialog : public QDialog { + Q_OBJECT + + public: + explicit Check_OutDialog(QWidget *parent = 0); + ~Check_OutDialog(); + + void initWindow(); + + private slots: + void on_pushButton_clicked(); + + void on_pushButton_2_clicked(); + + void on_comboBox_activated(const QString &arg1); + + void on_receipts_lineEdit_textEdited(const QString &arg1); + + private: + Ui::Check_OutDialog *ui; + void initCombox(); + SeatInfo *seat; +}; + +#endif // CHECK_OUTDIALOG_H diff --git a/src/rms/include/dialog/dayincomequery_dialog.h b/src/rms/include/dialog/dayincomequery_dialog.h new file mode 100644 index 0000000000000000000000000000000000000000..32fd2d565274b7e0cc130c881e0c8a17353af779 --- /dev/null +++ b/src/rms/include/dialog/dayincomequery_dialog.h @@ -0,0 +1,31 @@ +#ifndef DAYINCOMEQUERY_DIALOG_H +#define DAYINCOMEQUERY_DIALOG_H + +#include +#include +#include +#include + +namespace Ui { +class DayIncomeQuery_Dialog; +} + +class DayIncomeQuery_Dialog : public QDialog { + Q_OBJECT + + public: + explicit DayIncomeQuery_Dialog(QWidget *parent = 0); + ~DayIncomeQuery_Dialog(); + + void initCombox(); + + private slots: + void on_queryButton_clicked(); + + void on_quitButton_clicked(); + + private: + Ui::DayIncomeQuery_Dialog *ui; +}; + +#endif // DAYINCOMEQUERY_DIALOG_H diff --git a/src/include/dialog/dishescount_dialog.h b/src/rms/include/dialog/dishescount_dialog.h similarity index 100% rename from src/include/dialog/dishescount_dialog.h rename to src/rms/include/dialog/dishescount_dialog.h diff --git a/src/rms/include/dialog/foodinfo_dialog.h b/src/rms/include/dialog/foodinfo_dialog.h new file mode 100644 index 0000000000000000000000000000000000000000..f07de3d60fbe01be4b3ca790995539eca0331752 --- /dev/null +++ b/src/rms/include/dialog/foodinfo_dialog.h @@ -0,0 +1,35 @@ +#ifndef FOODINFO_DIALOG_H +#define FOODINFO_DIALOG_H + +#include +#include + +#include + +#include "db/food_info.h" + +namespace Ui { +class FoodInfo_Dialog; +} + +class FoodInfo_Dialog : public QDialog { + Q_OBJECT + + public: + explicit FoodInfo_Dialog(QWidget *parent = 0); + ~FoodInfo_Dialog(); + + private slots: + void on_deleteFood_Button_clicked(); + + void on_addFood_Button_clicked(); + + private: + Ui::FoodInfo_Dialog *ui; + + void initFood(); + + FoodInfo *foodInfo; +}; + +#endif // FOODINFO_DIALOG_H diff --git a/src/include/dialog/login_dialog.h b/src/rms/include/dialog/login_dialog.h similarity index 83% rename from src/include/dialog/login_dialog.h rename to src/rms/include/dialog/login_dialog.h index faf0ad32ec8312c08668ff149b7510d44a5ead6a..904c7a164059ed41733bf2b6a93ae71ddb1ee3bf 100644 --- a/src/include/dialog/login_dialog.h +++ b/src/rms/include/dialog/login_dialog.h @@ -5,7 +5,7 @@ #include #include -#include "src/include/db/user_management.h" +#include "db/user_management.h" namespace Ui { class LoginDialog; @@ -14,21 +14,21 @@ class LoginDialog; class LoginDialog : public QDialog { Q_OBJECT -public: + public: explicit LoginDialog(QWidget *parent = 0); ~LoginDialog(); bool VerifyPass(); bool returnAdmin(); -private slots: + private slots: void on_button_Login_clicked(); void on_button_Quit_clicked(); void on_button_Close_clicked(); -private: + private: Ui::LoginDialog *ui; bool pass; bool admin; @@ -36,4 +36,4 @@ private: // QSqlQuery query; }; -#endif // LOGINDIALOG_H +#endif // LOGINDIALOG_H diff --git a/src/rms/include/dialog/monthincomequery_dialog.h b/src/rms/include/dialog/monthincomequery_dialog.h new file mode 100644 index 0000000000000000000000000000000000000000..c470a6c1fedf96db2f7be417fedd24503528d46e --- /dev/null +++ b/src/rms/include/dialog/monthincomequery_dialog.h @@ -0,0 +1,34 @@ +#ifndef MONTHINCOMEQUERY_DIALOG_H +#define MONTHINCOMEQUERY_DIALOG_H + +#include +#include +#include +#include + +#include "db/search_sales.h" + +namespace Ui { +class MonthIncomeQuery_Dialog; +} + +class MonthIncomeQuery_Dialog : public QDialog { + Q_OBJECT + + public: + explicit MonthIncomeQuery_Dialog(QWidget *parent = 0); + ~MonthIncomeQuery_Dialog(); + + void initCombox(); + + private slots: + void on_queryButton_clicked(); + + void on_quitButton_clicked(); + + private: + Ui::MonthIncomeQuery_Dialog *ui; + QSqlDatabase m_db; +}; + +#endif // MONTHINCOMEQUERY_DIALOG_H diff --git a/src/rms/include/dialog/orderdishes_dialog.h b/src/rms/include/dialog/orderdishes_dialog.h new file mode 100644 index 0000000000000000000000000000000000000000..b2737f2559cfd83d9ed627991b058b1144b4c3de --- /dev/null +++ b/src/rms/include/dialog/orderdishes_dialog.h @@ -0,0 +1,45 @@ +#ifndef ORDERDISHESDIALOG_H +#define ORDERDISHESDIALOG_H + +#include +#include +#include +#include +#include +#include + +namespace Ui { +class OrderDishesDialog; +} + +class OrderDishesDialog : public QDialog { + Q_OBJECT + + public: + explicit OrderDishesDialog(QWidget *parent = 0); + ~OrderDishesDialog(); + + void receiverIdData(QString data); + QString returnTime(); + bool returnIsOrder(); + void initFoodTable(); + + private slots: + void on_OkButton_clicked(); + void on_cancelButton_clicked(); + void on_deleteButton_clicked(); + void on_addButton_clicked(); + + private: + Ui::OrderDishesDialog *ui; + QString idData; + int count; + QString dateStr; + //初始化菜单表 + bool isOrder; + + //窗口初始化 + void initWindow(); +}; + +#endif // ORDERDISHESDIALOG_H diff --git a/src/include/dialog/selectseat_dialog.h b/src/rms/include/dialog/selectseat_dialog.h similarity index 88% rename from src/include/dialog/selectseat_dialog.h rename to src/rms/include/dialog/selectseat_dialog.h index 2188c114de52f51185a32548db42577e7854a408..5c89250e3a74d46936980444db5109d3672c1bc6 100644 --- a/src/include/dialog/selectseat_dialog.h +++ b/src/rms/include/dialog/selectseat_dialog.h @@ -1,18 +1,17 @@ #ifndef SELECTSEATDIALOG_H #define SELECTSEATDIALOG_H -#include "orderdishes_dialog.h" #include +#include #include +#include #include #include -#include -#include -#include #include #include - -#include "src/include/db/seat_info.h" +#include +#include "db/seat_info.h" +#include "orderdishes_dialog.h" namespace Ui { class SelectSeat_Dialog; @@ -21,20 +20,20 @@ class SelectSeat_Dialog; class SelectSeat_Dialog : public QDialog { Q_OBJECT -public: + public: explicit SelectSeat_Dialog(QWidget *parent = 0); ~SelectSeat_Dialog(); //窗口初始化 void initWindow(); void deskInit(); -private slots: + private slots: void on_button_Ok_clicked(); void on_button_Cancel_clicked(); void on_tableWidget_clicked(const QModelIndex &index); void on_button_Close_clicked(); -private: + private: Ui::SelectSeat_Dialog *ui; QString idData; QString flagId; @@ -43,4 +42,4 @@ private: SeatInfo *seat; }; -#endif // SELECTSEATDIALOG_H +#endif // SELECTSEATDIALOG_H diff --git a/src/rms/include/dialog/staffregister_dialog.h b/src/rms/include/dialog/staffregister_dialog.h new file mode 100644 index 0000000000000000000000000000000000000000..3a941b17e2c29771a14ca97b531abfe13c8958d4 --- /dev/null +++ b/src/rms/include/dialog/staffregister_dialog.h @@ -0,0 +1,31 @@ +#ifndef STAFFREGISTER_DIALOG_H +#define STAFFREGISTER_DIALOG_H + +#include +#include +#include +#include + +namespace Ui { +class staffRegister_Dialog; +} + +class staffRegister_Dialog : public QDialog { + Q_OBJECT + + public: + explicit staffRegister_Dialog(QWidget *parent = 0); + ~staffRegister_Dialog(); + + private slots: + void on_pushButton_clicked(); + + void on_pushButton_2_clicked(); + + void on_cancel_pushButton_clicked(); + + private: + Ui::staffRegister_Dialog *ui; +}; + +#endif // STAFFREGISTER_DIALOG_H diff --git a/src/include/dialog/stockqquery_dialog.h b/src/rms/include/dialog/stockqquery_dialog.h similarity index 100% rename from src/include/dialog/stockqquery_dialog.h rename to src/rms/include/dialog/stockqquery_dialog.h diff --git a/src/include/dialog/varietymenu_dialog.h b/src/rms/include/dialog/varietymenu_dialog.h similarity index 100% rename from src/include/dialog/varietymenu_dialog.h rename to src/rms/include/dialog/varietymenu_dialog.h diff --git a/src/rms/include/main/mainwindow.h b/src/rms/include/main/mainwindow.h new file mode 100644 index 0000000000000000000000000000000000000000..758fc8e6fe941442653c6b829dc25855f844905f --- /dev/null +++ b/src/rms/include/main/mainwindow.h @@ -0,0 +1,51 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include "dialog/login_dialog.h" + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow { + Q_OBJECT + + public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + + void setEnabledMenu(bool e); //启用菜单 + + private slots: + void on_action_Login_triggered(); //系统登录触发器 + + void on_action_Quit_triggered(); //系统退出触发器 + + void on_action_Start_triggered(); //开始点菜触发器 + + void on_action_AddorReduce_triggered(); //加菜减菜触发器 + + void on_action_CustomerSettlement_triggered(); //顾客结账触发器 + + void on_action_DaySettlement_triggered(); //当日结算触发器 + + void on_action_UserRegistered_triggered(); //员工注册触发器 + + void on_action_DayIncomeQuery_triggered(); //日收入查询触发器 + + void on_action_MonthIncomeQuery_triggered(); //月收入查询触发器 + + void on_action_PurchaseQuery_triggered(); //进货查询触发器 + + void on_action_MenuInfo_triggered(); //菜单信息触发器 + + private: + Ui::MainWindow *ui; + + bool admin; //用户名 + bool pass; //密码 +}; + +#endif // MAINWINDOW_H diff --git a/src/include/ui/ui_add_reduce_dialog.h b/src/rms/include/ui/ui_add_reduce_dialog.h similarity index 100% rename from src/include/ui/ui_add_reduce_dialog.h rename to src/rms/include/ui/ui_add_reduce_dialog.h diff --git a/src/include/ui/ui_check_out_dialog.h b/src/rms/include/ui/ui_check_out_dialog.h similarity index 100% rename from src/include/ui/ui_check_out_dialog.h rename to src/rms/include/ui/ui_check_out_dialog.h diff --git a/src/include/ui/ui_dayincomequery_dialog.h b/src/rms/include/ui/ui_dayincomequery_dialog.h similarity index 100% rename from src/include/ui/ui_dayincomequery_dialog.h rename to src/rms/include/ui/ui_dayincomequery_dialog.h diff --git a/src/include/ui/ui_dishescount_dialog.h b/src/rms/include/ui/ui_dishescount_dialog.h similarity index 100% rename from src/include/ui/ui_dishescount_dialog.h rename to src/rms/include/ui/ui_dishescount_dialog.h diff --git a/src/include/ui/ui_foodinfo_dialog.h b/src/rms/include/ui/ui_foodinfo_dialog.h similarity index 100% rename from src/include/ui/ui_foodinfo_dialog.h rename to src/rms/include/ui/ui_foodinfo_dialog.h diff --git a/src/include/ui/ui_login_dialog.h b/src/rms/include/ui/ui_login_dialog.h similarity index 100% rename from src/include/ui/ui_login_dialog.h rename to src/rms/include/ui/ui_login_dialog.h diff --git a/src/include/ui/ui_mainwindow.h b/src/rms/include/ui/ui_mainwindow.h similarity index 100% rename from src/include/ui/ui_mainwindow.h rename to src/rms/include/ui/ui_mainwindow.h diff --git a/src/include/ui/ui_monthincomequery_dialog.h b/src/rms/include/ui/ui_monthincomequery_dialog.h similarity index 100% rename from src/include/ui/ui_monthincomequery_dialog.h rename to src/rms/include/ui/ui_monthincomequery_dialog.h diff --git a/src/include/ui/ui_orderdishes_dialog.h b/src/rms/include/ui/ui_orderdishes_dialog.h similarity index 100% rename from src/include/ui/ui_orderdishes_dialog.h rename to src/rms/include/ui/ui_orderdishes_dialog.h diff --git a/src/include/ui/ui_selectseat_dialog.h b/src/rms/include/ui/ui_selectseat_dialog.h similarity index 100% rename from src/include/ui/ui_selectseat_dialog.h rename to src/rms/include/ui/ui_selectseat_dialog.h diff --git a/src/include/ui/ui_staffregister_dialog.h b/src/rms/include/ui/ui_staffregister_dialog.h similarity index 100% rename from src/include/ui/ui_staffregister_dialog.h rename to src/rms/include/ui/ui_staffregister_dialog.h diff --git a/src/include/ui/ui_stockquery_dialog.h b/src/rms/include/ui/ui_stockquery_dialog.h similarity index 100% rename from src/include/ui/ui_stockquery_dialog.h rename to src/rms/include/ui/ui_stockquery_dialog.h diff --git a/src/include/ui/ui_varietymenu_dialog.h b/src/rms/include/ui/ui_varietymenu_dialog.h similarity index 100% rename from src/include/ui/ui_varietymenu_dialog.h rename to src/rms/include/ui/ui_varietymenu_dialog.h diff --git a/src/sources/db/check.cpp b/src/rms/sources/db/check.cpp similarity index 96% rename from src/sources/db/check.cpp rename to src/rms/sources/db/check.cpp index 71842ec4dcd12b50e24bd110dd9a077aff5a3d0a..f421dc9504f0a5ed4a4945afdc5cf77341b44a45 100644 --- a/src/sources/db/check.cpp +++ b/src/rms/sources/db/check.cpp @@ -1,4 +1,4 @@ -#include "src/include/db/check.h" +#include "db/check.h" Check::Check() {} diff --git a/src/sources/db/create_table.cpp b/src/rms/sources/db/create_table.cpp similarity index 86% rename from src/sources/db/create_table.cpp rename to src/rms/sources/db/create_table.cpp index 15a1f935f90b9cc34e4345f023977f89482287e9..7a96fe7f824248b1984839fa60fc9e49fdb58b71 100644 --- a/src/sources/db/create_table.cpp +++ b/src/rms/sources/db/create_table.cpp @@ -1,5 +1,5 @@ -#include "src/include/db/create_table.h" -#include "src/include/db/excute_sql_file.h" +#include "db/create_table.h" +#include "db/excute_sql_file.h" CreateTable::CreateTable() {} diff --git a/src/sources/db/day_statistics.cpp b/src/rms/sources/db/day_statistics.cpp similarity index 94% rename from src/sources/db/day_statistics.cpp rename to src/rms/sources/db/day_statistics.cpp index a15ebfd0c4a3d2577ccc229724f7c0fdd3d7e846..1c85443b1e299ae133e6c128d251714b374cf0b2 100644 --- a/src/sources/db/day_statistics.cpp +++ b/src/rms/sources/db/day_statistics.cpp @@ -1,4 +1,4 @@ -#include "src/include/db/day_statistics.h" +#include "db/day_statistics.h" DayStatistics::DayStatistics() {} diff --git a/src/sources/db/excute_sql_file.cpp b/src/rms/sources/db/excute_sql_file.cpp similarity index 92% rename from src/sources/db/excute_sql_file.cpp rename to src/rms/sources/db/excute_sql_file.cpp index 454258dbf89b9ef8e0b428aec7bdd8d4f95ece42..c53e1043569c31d2d2660afac645745e25512f20 100644 --- a/src/sources/db/excute_sql_file.cpp +++ b/src/rms/sources/db/excute_sql_file.cpp @@ -1,5 +1,5 @@ -#include "src/include/db/excute_sql_file.h" -#include "src/include/db/manage_databese.h" +#include "db/excute_sql_file.h" +#include "db/manage_databese.h" ExcuteSqlFile::ExcuteSqlFile() {} diff --git a/src/sources/db/food_info.cpp b/src/rms/sources/db/food_info.cpp similarity index 97% rename from src/sources/db/food_info.cpp rename to src/rms/sources/db/food_info.cpp index ce15dd0d0be28592058b2caab030fc8cfb8706aa..ccc5ef140ee49bc84f79006823c7625128c3defe 100644 --- a/src/sources/db/food_info.cpp +++ b/src/rms/sources/db/food_info.cpp @@ -1,4 +1,4 @@ -#include "src/include/db/food_info.h" +#include "db/food_info.h" FoodInfo::FoodInfo() {} diff --git a/src/sources/db/init_database.cpp b/src/rms/sources/db/init_database.cpp similarity index 92% rename from src/sources/db/init_database.cpp rename to src/rms/sources/db/init_database.cpp index 28b75f2d80aac8ca5a0d88d10cb3df2101e921c8..cfb61f278cd34fadf2cae674455f804d1b21b3eb 100644 --- a/src/sources/db/init_database.cpp +++ b/src/rms/sources/db/init_database.cpp @@ -1,6 +1,6 @@ -#include "src/include/db/init_database.h" -#include "src/include/db/create_table.h" -#include "src/include/db/manage_databese.h" +#include "db/init_database.h" +#include "db/create_table.h" +#include "db/manage_databese.h" InitDatabase::InitDatabase() {} diff --git a/src/sources/db/manage_databese.cpp b/src/rms/sources/db/manage_databese.cpp similarity index 83% rename from src/sources/db/manage_databese.cpp rename to src/rms/sources/db/manage_databese.cpp index 034efca41a4fe1ace413db8463eb0f658d705698..578b86d67f9f26ae32c630fcfdb2d27ee9e17919 100644 --- a/src/sources/db/manage_databese.cpp +++ b/src/rms/sources/db/manage_databese.cpp @@ -1,5 +1,5 @@ -#include "src/include/db/manage_databese.h" -#include "src/include/db/create_table.h" +#include "db/manage_databese.h" +#include "db/create_table.h" ManageDatabese::ManageDatabese() {} diff --git a/src/sources/db/order_dishes.cpp b/src/rms/sources/db/order_dishes.cpp similarity index 98% rename from src/sources/db/order_dishes.cpp rename to src/rms/sources/db/order_dishes.cpp index a2cb356fbc7871fe36c2e4befc5539ac6097c281..0089ba3ac30f1d349f5054a6a31b5901ae9d8dc3 100644 --- a/src/sources/db/order_dishes.cpp +++ b/src/rms/sources/db/order_dishes.cpp @@ -1,4 +1,4 @@ -#include "src/include/db/order_dishes.h" +#include "db/order_dishes.h" OrderDishes::OrderDishes() {} diff --git a/src/sources/db/search_sales.cpp b/src/rms/sources/db/search_sales.cpp similarity index 96% rename from src/sources/db/search_sales.cpp rename to src/rms/sources/db/search_sales.cpp index 1556b4c6f95e1315d6602afac74e4571b8ef1016..ee46f14932bd6a760378577997163f14b1c1d6a6 100644 --- a/src/sources/db/search_sales.cpp +++ b/src/rms/sources/db/search_sales.cpp @@ -1,4 +1,4 @@ -#include "src/include/db/search_sales.h" +#include "db/search_sales.h" SearchSales::SearchSales() {} diff --git a/src/sources/db/seat_info.cpp b/src/rms/sources/db/seat_info.cpp similarity index 97% rename from src/sources/db/seat_info.cpp rename to src/rms/sources/db/seat_info.cpp index b020e62115736d3a31b17332876d54ba4ce1a96d..84e431af4e39ef83db9af7ec0ad52ef3bfcf413e 100644 --- a/src/sources/db/seat_info.cpp +++ b/src/rms/sources/db/seat_info.cpp @@ -1,4 +1,4 @@ -#include "src/include/db/seat_info.h" +#include "db/seat_info.h" SeatInfo::SeatInfo() {} diff --git a/src/sources/db/user_management.cpp b/src/rms/sources/db/user_management.cpp similarity index 96% rename from src/sources/db/user_management.cpp rename to src/rms/sources/db/user_management.cpp index c5e615087b6f0a5197b79677b17646e6527bd5a2..e9bb62ebff0b5ddebaa0fefdcac201ca9af5d9fc 100644 --- a/src/sources/db/user_management.cpp +++ b/src/rms/sources/db/user_management.cpp @@ -1,4 +1,4 @@ -#include "src/include/db/user_management.h" +#include "db/user_management.h" UserManagement::UserManagement() {} diff --git a/src/sources/dialog/add_reduce_dialog.cpp b/src/rms/sources/dialog/add_reduce_dialog.cpp similarity index 78% rename from src/sources/dialog/add_reduce_dialog.cpp rename to src/rms/sources/dialog/add_reduce_dialog.cpp index 6acd1bc6e083b9bc9b82634c9322f417b205195f..ae09f98dd9ed624114b65fb518bfa57a19ca458a 100644 --- a/src/sources/dialog/add_reduce_dialog.cpp +++ b/src/rms/sources/dialog/add_reduce_dialog.cpp @@ -1,6 +1,7 @@ -#include "src/include/dialog/add_reduce_dialog.h" -#include "src/include/dialog/dishescount_dialog.h" -#include "src/include/ui/ui_add_reduce_dialog.h" +#include "dialog/add_reduce_dialog.h" +#include "db/food_info.h" +#include "dialog/dishescount_dialog.h" +#include "ui/ui_add_reduce_dialog.h" Add_Reduce_Dialog::Add_Reduce_Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Add_Reduce_Dialog) { @@ -21,19 +22,15 @@ Add_Reduce_Dialog::Add_Reduce_Dialog(QWidget *parent) dishes = new OrderDishes(); } -Add_Reduce_Dialog::~Add_Reduce_Dialog() { - delete ui; -} +Add_Reduce_Dialog::~Add_Reduce_Dialog() { delete ui; } void Add_Reduce_Dialog::on_okButton_clicked() { - QString tableId = ui->comboBox->currentText(); QAbstractItemModel *rightModel = ui->isAddFood_tableWidget->model(); QAbstractItemModel *leftModel = ui->food_tableWidget->model(); - dishes->UpdateDishes(tableId,rightModel ,leftModel); + dishes->UpdateDishes(tableId, rightModel, leftModel); qDebug() << tableId; - this->close(); } @@ -78,16 +75,18 @@ void Add_Reduce_Dialog::on_deleteButton_clicked() { } void Add_Reduce_Dialog::initFoodTable() { - QStringList *foodNameItem=new QStringList(); - QStringList *foodPriceItem=new QStringList(); - int row=0; - FoodInfo *foodInfo= new FoodInfo(); - foodInfo->searchFoodInfo(foodNameItem,foodPriceItem,&row); - ui->food_tableWidget->setRowCount(row); - for(int i=0;isize();i++){ - ui->food_tableWidget->setItem(i, 0, new QTableWidgetItem(foodNameItem->at(i))); - ui->food_tableWidget->setItem(i, 1, new QTableWidgetItem(foodPriceItem->at(i))); - } + QStringList *foodNameItem = new QStringList(); + QStringList *foodPriceItem = new QStringList(); + int row = 0; + FoodInfo *foodInfo = new FoodInfo(); + foodInfo->searchFoodInfo(foodNameItem, foodPriceItem, &row); + ui->food_tableWidget->setRowCount(row); + for (int i = 0; i < foodNameItem->size(); i++) { + ui->food_tableWidget->setItem(i, 0, + new QTableWidgetItem(foodNameItem->at(i))); + ui->food_tableWidget->setItem(i, 1, + new QTableWidgetItem(foodPriceItem->at(i))); + } } void Add_Reduce_Dialog::initCombox() { @@ -116,7 +115,7 @@ void Add_Reduce_Dialog::initWindowFoodTable() { //设置选中背景色 ui->food_tableWidget->setStyleSheet("selection-background-color:lightblue;"); ui->food_tableWidget->setSelectionMode( - QAbstractItemView::SingleSelection); //设置为可以选中单个 + QAbstractItemView::SingleSelection); //设置为可以选中单个 } void Add_Reduce_Dialog::initWindowIsAddTable() { @@ -143,7 +142,7 @@ void Add_Reduce_Dialog::initWindowIsAddTable() { ui->isAddFood_tableWidget->setStyleSheet( "selection-background-color:lightblue;"); ui->isAddFood_tableWidget->setSelectionMode( - QAbstractItemView::SingleSelection); //设置为可以选中单个 + QAbstractItemView::SingleSelection); //设置为可以选中单个 ui->isAddFood_tableWidget->setRowCount(50); } @@ -171,15 +170,17 @@ void Add_Reduce_Dialog::initWindowIsAddTable() { //} void Add_Reduce_Dialog::on_comboBox_activated(const QString &arg1) { - ui->isAddFood_tableWidget->clear(); - - QStringList *foodNameItem=new QStringList(); - QStringList *foodPriceItem=new QStringList(); - - dishes->chooseDishes(arg1,foodNameItem,foodPriceItem); - for(int i=0;isize();i++){ - ui->isAddFood_tableWidget->setItem(i, 0, new QTableWidgetItem(foodNameItem->at(i))); - ui->isAddFood_tableWidget->setItem(i, 1, new QTableWidgetItem(foodPriceItem->at(i))); - count = ++i; - } + ui->isAddFood_tableWidget->clear(); + + QStringList *foodNameItem = new QStringList(); + QStringList *foodPriceItem = new QStringList(); + + dishes->chooseDishes(arg1, foodNameItem, foodPriceItem); + for (int i = 0; i < foodNameItem->size(); i++) { + ui->isAddFood_tableWidget->setItem( + i, 0, new QTableWidgetItem(foodNameItem->at(i))); + ui->isAddFood_tableWidget->setItem( + i, 1, new QTableWidgetItem(foodPriceItem->at(i))); + count = ++i; + } } diff --git a/src/sources/dialog/check_out_dialog.cpp b/src/rms/sources/dialog/check_out_dialog.cpp similarity index 71% rename from src/sources/dialog/check_out_dialog.cpp rename to src/rms/sources/dialog/check_out_dialog.cpp index d412850d8e821e277f7150342b2dafddac82e6b8..f1e3f0fe96682008a74a25a8cba7e6a77375ecf6 100644 --- a/src/sources/dialog/check_out_dialog.cpp +++ b/src/rms/sources/dialog/check_out_dialog.cpp @@ -1,24 +1,23 @@ -#include "src/include/dialog/check_out_dialog.h" -#include "src/include/ui/ui_check_out_dialog.h" -#include +#include "dialog/check_out_dialog.h" +#include "db/check.h" +#include "ui/ui_check_out_dialog.h" Check_OutDialog::Check_OutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Check_OutDialog) { ui->setupUi(this); this->setWindowTitle("结帐"); - seat=new SeatInfo(); + seat = new SeatInfo(); initWindow(); initCombox(); } Check_OutDialog::~Check_OutDialog() { - delete ui; - seat->~SeatInfo(); + delete ui; + seat->~SeatInfo(); } void Check_OutDialog::initWindow() { - QBrush myBrush; QPalette palette; myBrush = QBrush(Qt::blue, Qt::DiagCrossPattern); @@ -56,15 +55,15 @@ void Check_OutDialog::initWindow() { // ui->tableWidget->setEnabled(false); ui->tableWidget->setStyleSheet("selection-background-color:lightblue;"); ui->tableWidget->setSelectionMode( - QAbstractItemView::SingleSelection); //设置为可以选中单个 + QAbstractItemView::SingleSelection); //设置为可以选中单个 ui->tableWidget->setRowCount(50); } void Check_OutDialog::on_pushButton_clicked() { QString tableid = ui->comboBox->currentText(); - QString time=""; - QString isSomeone="没人"; - seat->updateSeatInfo(time,tableid,isSomeone); + QString time = ""; + QString isSomeone = "没人"; + seat->updateSeatInfo(time, tableid, isSomeone); QMessageBox::information(this, "温馨提示", "已成功收款!再见!"); this->close(); } @@ -77,19 +76,18 @@ void Check_OutDialog::on_comboBox_activated(const QString &arg1) { ui->receivable_lineEdit->clear(); ui->change_lineEdit->clear(); - QStringList *foodNameList=new QStringList(); - QStringList *foodPriceList=new QStringList(); - QStringList *numberList=new QStringList(); - Check *check=new Check(); - QString sumMoney=check->checkOut(arg1,foodNameList,foodPriceList,numberList); + QStringList *foodNameList = new QStringList(); + QStringList *foodPriceList = new QStringList(); + QStringList *numberList = new QStringList(); + Check *check = new Check(); + QString sumMoney = + check->checkOut(arg1, foodNameList, foodPriceList, numberList); - for(int i=0; isize();i++){ - ui->tableWidget->setItem(i, 0, new QTableWidgetItem(foodNameList->at(i))); - ui->tableWidget->setItem(i, 1, - new QTableWidgetItem(numberList->at(i))); - ui->tableWidget->setItem(i, 2, - new QTableWidgetItem(foodPriceList->at(i))); - } + for (int i = 0; i < foodNameList->size(); i++) { + ui->tableWidget->setItem(i, 0, new QTableWidgetItem(foodNameList->at(i))); + ui->tableWidget->setItem(i, 1, new QTableWidgetItem(numberList->at(i))); + ui->tableWidget->setItem(i, 2, new QTableWidgetItem(foodPriceList->at(i))); + } ui->receivable_lineEdit->setText(sumMoney); //销毁对象 @@ -99,12 +97,12 @@ void Check_OutDialog::on_comboBox_activated(const QString &arg1) { } void Check_OutDialog::initCombox() { - ui->comboBox->addItems(seat->searchSomeSeat()); + ui->comboBox->addItems(seat->searchSomeSeat()); } void Check_OutDialog::on_receipts_lineEdit_textEdited(const QString &arg1) { double receipts = arg1.toDouble(); - QString sumMoney=ui->receivable_lineEdit->text(); + QString sumMoney = ui->receivable_lineEdit->text(); double chang = receipts - sumMoney.toDouble(); ui->change_lineEdit->setText(QString::number(chang)); } diff --git a/src/sources/dialog/dayincomequery_dialog.cpp b/src/rms/sources/dialog/dayincomequery_dialog.cpp similarity index 81% rename from src/sources/dialog/dayincomequery_dialog.cpp rename to src/rms/sources/dialog/dayincomequery_dialog.cpp index d1e303b725a516d93ec12517f97458d96ebffcb9..87a6ee85708bea4f064104658cf0d32622055e3e 100644 --- a/src/sources/dialog/dayincomequery_dialog.cpp +++ b/src/rms/sources/dialog/dayincomequery_dialog.cpp @@ -1,5 +1,6 @@ -#include "src/include/dialog/dayincomequery_dialog.h" -#include "src/include/ui/ui_dayincomequery_dialog.h" +#include "dialog/dayincomequery_dialog.h" +#include "db/search_sales.h" +#include "ui/ui_dayincomequery_dialog.h" DayIncomeQuery_Dialog::DayIncomeQuery_Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::DayIncomeQuery_Dialog) { @@ -44,12 +45,11 @@ void DayIncomeQuery_Dialog::on_queryButton_clicked() { QString month = ui->month_comboBox->currentText(); QString day = ui->day_comboBox->currentText(); - SearchSales *sales=new SearchSales(); - QString sumMoney=sales->searchDailySales(year,month,day); + SearchSales *sales = new SearchSales(); + QString sumMoney = sales->searchDailySales(year, month, day); QMessageBox::information(this, "日收入查询", "" + year + "年" + month + "月" + day + - "日的收入为: " + sumMoney + - " 元"); + "日的收入为: " + sumMoney + " 元"); } void DayIncomeQuery_Dialog::on_quitButton_clicked() { this->close(); } diff --git a/src/sources/dialog/dishescount_dialog.cpp b/src/rms/sources/dialog/dishescount_dialog.cpp similarity index 87% rename from src/sources/dialog/dishescount_dialog.cpp rename to src/rms/sources/dialog/dishescount_dialog.cpp index a928322e140e038ad1b2559c5ad259dc44a23589..a1a30fefd07bd465516cbe421b800674925602df 100644 --- a/src/sources/dialog/dishescount_dialog.cpp +++ b/src/rms/sources/dialog/dishescount_dialog.cpp @@ -1,7 +1,7 @@ -#include "src/include/dialog/dishescount_dialog.h" -#include "src/include/ui/ui_dishescount_dialog.h" +#include "dialog/dishescount_dialog.h" #include #include +#include "ui/ui_dishescount_dialog.h" DishesCountDialog::DishesCountDialog(QWidget *parent) : QDialog(parent), ui(new Ui::DishesCountDialog) { diff --git a/src/sources/dialog/foodinfo_dialog.cpp b/src/rms/sources/dialog/foodinfo_dialog.cpp similarity index 73% rename from src/sources/dialog/foodinfo_dialog.cpp rename to src/rms/sources/dialog/foodinfo_dialog.cpp index 3065c605d5866459de47b3588832a7c03ebadae3..49ca9764e39d8a11f86d5ac638968c3d36049a72 100644 --- a/src/sources/dialog/foodinfo_dialog.cpp +++ b/src/rms/sources/dialog/foodinfo_dialog.cpp @@ -1,5 +1,5 @@ -#include "src/include/dialog/foodinfo_dialog.h" -#include "src/include/ui/ui_foodinfo_dialog.h" +#include "dialog/foodinfo_dialog.h" +#include "ui/ui_foodinfo_dialog.h" FoodInfo_Dialog::FoodInfo_Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::FoodInfo_Dialog) { @@ -27,7 +27,7 @@ FoodInfo_Dialog::FoodInfo_Dialog(QWidget *parent) ui->tableWidget->setStyleSheet("selection-background-color:lightblue;"); ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection); - foodInfo= new FoodInfo(); + foodInfo = new FoodInfo(); initFood(); } @@ -48,7 +48,7 @@ void FoodInfo_Dialog::on_addFood_Button_clicked() { QString foodName = ui->foodName_lineEdit->text(); QString foodPrice = ui->foodPrice_lineEdit->text(); if ("" != foodName && "" != foodPrice) { - foodInfo->insertFoodInfo(foodName,foodPrice); + foodInfo->insertFoodInfo(foodName, foodPrice); initFood(); } ui->foodName_lineEdit->clear(); @@ -56,14 +56,14 @@ void FoodInfo_Dialog::on_addFood_Button_clicked() { } void FoodInfo_Dialog::initFood() { - QStringList *foodNameItem=new QStringList(); - QStringList *foodPriceItem=new QStringList(); - int row=0; - foodInfo->searchFoodInfo(foodNameItem,foodPriceItem,&row); - ui->tableWidget->setRowCount(row); + QStringList *foodNameItem = new QStringList(); + QStringList *foodPriceItem = new QStringList(); + int row = 0; + foodInfo->searchFoodInfo(foodNameItem, foodPriceItem, &row); + ui->tableWidget->setRowCount(row); - for(int i=0;isize();i++){ - ui->tableWidget->setItem(i, 0, new QTableWidgetItem(foodNameItem->at(i))); - ui->tableWidget->setItem(i, 1, new QTableWidgetItem(foodPriceItem->at(i))); - } + for (int i = 0; i < foodNameItem->size(); i++) { + ui->tableWidget->setItem(i, 0, new QTableWidgetItem(foodNameItem->at(i))); + ui->tableWidget->setItem(i, 1, new QTableWidgetItem(foodPriceItem->at(i))); + } } diff --git a/src/sources/dialog/login_dialog.cpp b/src/rms/sources/dialog/login_dialog.cpp similarity index 76% rename from src/sources/dialog/login_dialog.cpp rename to src/rms/sources/dialog/login_dialog.cpp index 92d3d338d9e3ddb37562b6bc03b2dc5e3239a652..a91b40e04fb32e72569eb2c518641c4ad930e0f1 100644 --- a/src/sources/dialog/login_dialog.cpp +++ b/src/rms/sources/dialog/login_dialog.cpp @@ -1,5 +1,5 @@ -#include "src/include/dialog/login_dialog.h" -#include "src/include/ui/ui_login_dialog.h" +#include "dialog/login_dialog.h" +#include "ui/ui_login_dialog.h" LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::LoginDialog) { @@ -26,13 +26,13 @@ void LoginDialog::on_button_Login_clicked() { QMessageBox::information(this, "登录提示", "请输入登录名"); } else if (NULL == userpassword) { QMessageBox::information(this, "登录提示", "请输入登录密码"); - } else { - UserManagement *user=new UserManagement(); - flag=user->login(username,userpassword); + } else { + UserManagement *user = new UserManagement(); + flag = user->login(username, userpassword); } - if(flag){ - QMessageBox::information(this, "登录提示", "密码或者用户名错误"); + if (flag) { + QMessageBox::information(this, "登录提示", "密码或者用户名错误"); } } diff --git a/src/sources/dialog/monthincomequery_dialog.cpp b/src/rms/sources/dialog/monthincomequery_dialog.cpp similarity index 73% rename from src/sources/dialog/monthincomequery_dialog.cpp rename to src/rms/sources/dialog/monthincomequery_dialog.cpp index 570f6413ac335000e07b69cbf0497f5a9a9805af..07052bd1e25969c74b1a85d5991ca9db08d86905 100644 --- a/src/sources/dialog/monthincomequery_dialog.cpp +++ b/src/rms/sources/dialog/monthincomequery_dialog.cpp @@ -1,5 +1,5 @@ -#include "src/include/dialog/monthincomequery_dialog.h" -#include "src/include/ui/ui_monthincomequery_dialog.h" +#include "dialog/monthincomequery_dialog.h" +#include "ui/ui_monthincomequery_dialog.h" MonthIncomeQuery_Dialog::MonthIncomeQuery_Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::MonthIncomeQuery_Dialog) { @@ -34,11 +34,11 @@ void MonthIncomeQuery_Dialog::on_queryButton_clicked() { QString year = ui->year_comboBox->currentText(); QString month = ui->month_comboBox->currentText(); - SearchSales *sales=new SearchSales(); - QString sumMoney=sales->searchMonthSales(year,month); - QMessageBox::information(this, "月收入查询", - "" + year + "年" + month + "月的收入为: " + - sumMoney + " 元"); + SearchSales *sales = new SearchSales(); + QString sumMoney = sales->searchMonthSales(year, month); + QMessageBox::information( + this, "月收入查询", + "" + year + "年" + month + "月的收入为: " + sumMoney + " 元"); } void MonthIncomeQuery_Dialog::on_quitButton_clicked() { this->close(); } diff --git a/src/sources/dialog/orderdishes_dialog.cpp b/src/rms/sources/dialog/orderdishes_dialog.cpp similarity index 80% rename from src/sources/dialog/orderdishes_dialog.cpp rename to src/rms/sources/dialog/orderdishes_dialog.cpp index 6bf26f8a4a510f40e241ccb420287c77e0f91a2e..959496c9a361afaa29ef77f664869a6c0b2efe53 100644 --- a/src/sources/dialog/orderdishes_dialog.cpp +++ b/src/rms/sources/dialog/orderdishes_dialog.cpp @@ -1,7 +1,9 @@ -#include "src/include/dialog/dishescount_dialog.h" -#include "src/include/ui/ui_orderdishes_dialog.h" -#include "src/include/dialog/orderdishes_dialog.h" +#include "dialog/orderdishes_dialog.h" #include +#include "db/food_info.h" +#include "db/order_dishes.h" +#include "dialog/dishescount_dialog.h" +#include "ui/ui_orderdishes_dialog.h" OrderDishesDialog::OrderDishesDialog(QWidget *parent) : QDialog(parent), ui(new Ui::OrderDishesDialog) { @@ -29,9 +31,7 @@ OrderDishesDialog::OrderDishesDialog(QWidget *parent) initWindow(); } -OrderDishesDialog::~OrderDishesDialog() { - delete ui; -} +OrderDishesDialog::~OrderDishesDialog() { delete ui; } void OrderDishesDialog::receiverIdData(QString data) { idData = data; @@ -41,18 +41,18 @@ void OrderDishesDialog::receiverIdData(QString data) { bool OrderDishesDialog::returnIsOrder() { return isOrder; } void OrderDishesDialog::on_OkButton_clicked() { - QAbstractItemModel *rightModel = ui->isSelcteFood_tableWidget->model(); - QAbstractItemModel *leftModel = ui->food_tableWidget->model(); + QAbstractItemModel *rightModel = ui->isSelcteFood_tableWidget->model(); + QAbstractItemModel *leftModel = ui->food_tableWidget->model(); - OrderDishes *dishes=new OrderDishes(); - dishes->UpdateDishes(idData,rightModel,leftModel); + OrderDishes *dishes = new OrderDishes(); + dishes->UpdateDishes(idData, rightModel, leftModel); QMessageBox::information(this, "温馨提示", "点菜成功"); this->close(); } void OrderDishesDialog::on_cancelButton_clicked() { - this->close(); //关闭窗口 + this->close(); //关闭窗口 } void OrderDishesDialog::on_deleteButton_clicked() { QAbstractItemModel *model = ui->isSelcteFood_tableWidget->model(); @@ -125,7 +125,7 @@ void OrderDishesDialog::initWindow() { //设置选中背景色 ui->food_tableWidget->setStyleSheet("selection-background-color:lightblue;"); ui->food_tableWidget->setSelectionMode( - QAbstractItemView::SingleSelection); //设置为可以选中单个 + QAbstractItemView::SingleSelection); //设置为可以选中单个 //初始化菜单 // initFoodTable(); @@ -155,23 +155,25 @@ void OrderDishesDialog::initWindow() { ui->isSelcteFood_tableWidget->setStyleSheet( "selection-background-color:lightblue;"); ui->isSelcteFood_tableWidget->setSelectionMode( - QAbstractItemView::SingleSelection); //设置为可以选中单个 + QAbstractItemView::SingleSelection); //设置为可以选中单个 ui->isSelcteFood_tableWidget->setRowCount(50); } void OrderDishesDialog::initFoodTable() { - QStringList *foodNameItem=new QStringList(); - QStringList *foodPriceItem=new QStringList(); - - int row=0; - FoodInfo *foodInfo=new FoodInfo(); - foodInfo->searchFoodInfo(foodNameItem,foodPriceItem,&row); - ui->food_tableWidget->setRowCount(row); - - for (int i=0;isize();i++) { - ui->food_tableWidget->setItem(i, 0, new QTableWidgetItem(foodNameItem->at(i))); - ui->food_tableWidget->setItem(i, 1, new QTableWidgetItem(foodPriceItem->at(i))); - } + QStringList *foodNameItem = new QStringList(); + QStringList *foodPriceItem = new QStringList(); + + int row = 0; + FoodInfo *foodInfo = new FoodInfo(); + foodInfo->searchFoodInfo(foodNameItem, foodPriceItem, &row); + ui->food_tableWidget->setRowCount(row); + + for (int i = 0; i < foodNameItem->size(); i++) { + ui->food_tableWidget->setItem(i, 0, + new QTableWidgetItem(foodNameItem->at(i))); + ui->food_tableWidget->setItem(i, 1, + new QTableWidgetItem(foodPriceItem->at(i))); + } } QString OrderDishesDialog::returnTime() { return dateStr; } diff --git a/src/sources/dialog/selectseat_dialog.cpp b/src/rms/sources/dialog/selectseat_dialog.cpp similarity index 77% rename from src/sources/dialog/selectseat_dialog.cpp rename to src/rms/sources/dialog/selectseat_dialog.cpp index b5342e2a98a39470a205e82623aa1b64f744583d..d1ee915a7f0a9482c328c2b6ad4868b3d784fdd1 100644 --- a/src/sources/dialog/selectseat_dialog.cpp +++ b/src/rms/sources/dialog/selectseat_dialog.cpp @@ -1,5 +1,5 @@ -#include "src/include/dialog/selectseat_dialog.h" -#include "src/include/ui/ui_selectseat_dialog.h" +#include "dialog/selectseat_dialog.h" +#include "ui/ui_selectseat_dialog.h" SelectSeat_Dialog::SelectSeat_Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::SelectSeat_Dialog) { @@ -7,8 +7,8 @@ SelectSeat_Dialog::SelectSeat_Dialog(QWidget *parent) this->setWindowTitle("请选择座位"); orderDishes = new OrderDishesDialog; - idData = ""; //初始化数据 - seat=new SeatInfo(); + idData = ""; //初始化数据 + seat = new SeatInfo(); initWindow(); deskInit(); } @@ -30,9 +30,9 @@ void SelectSeat_Dialog::initWindow() { //设置表格显示 ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); ui->tableWidget->setSelectionBehavior( - QAbstractItemView::SelectRows); //选中整行 + QAbstractItemView::SelectRows); //选中整行 // ui->tableWidget->item(0,0)->setTextAlignment(Qt::AlignHCenter);//选择对齐方式 - ui->tableWidget->setAlternatingRowColors(true); //设置每行变一色 + ui->tableWidget->setAlternatingRowColors(true); //设置每行变一色 ui->tableWidget->setColumnCount(2); QStringList list; list << "桌号" @@ -50,7 +50,7 @@ void SelectSeat_Dialog::initWindow() { //设置选中背景色 ui->tableWidget->setStyleSheet("selection-background-color:lightblue;"); ui->tableWidget->setSelectionMode( - QAbstractItemView::SingleSelection); //设置为可以选中单个 + QAbstractItemView::SingleSelection); //设置为可以选中单个 } void SelectSeat_Dialog::on_button_Ok_clicked() { @@ -73,8 +73,8 @@ void SelectSeat_Dialog::on_button_Ok_clicked() { QString idTable = ui->lineEdit_Id->text(); qDebug() << idData; //数据更新操作 - QString isSomeone="有人"; - if (seat->updateSeatInfo(time,idTable,isSomeone)){ + QString isSomeone = "有人"; + if (seat->updateSeatInfo(time, idTable, isSomeone)) { qDebug() << "打开成功"; } deskInit(); @@ -100,15 +100,15 @@ void SelectSeat_Dialog::on_tableWidget_clicked(const QModelIndex &index) { } void SelectSeat_Dialog::deskInit() { - QStringList *deskIdItem=new QStringList(); - QStringList *flagItem =new QStringList(); - int row=0; - seat->searchSeatInfo(deskIdItem,flagItem,&row); - ui->tableWidget->setRowCount(row); - for(int i=0; isize();i++){ - ui->tableWidget->setItem(i, 0, new QTableWidgetItem(deskIdItem->at(i))); - ui->tableWidget->setItem(i, 1, new QTableWidgetItem(flagItem->at(i))); - } + QStringList *deskIdItem = new QStringList(); + QStringList *flagItem = new QStringList(); + int row = 0; + seat->searchSeatInfo(deskIdItem, flagItem, &row); + ui->tableWidget->setRowCount(row); + for (int i = 0; i < deskIdItem->size(); i++) { + ui->tableWidget->setItem(i, 0, new QTableWidgetItem(deskIdItem->at(i))); + ui->tableWidget->setItem(i, 1, new QTableWidgetItem(flagItem->at(i))); + } } void SelectSeat_Dialog::on_button_Close_clicked() { this->close(); } diff --git a/src/sources/dialog/staffregister_dialog.cpp b/src/rms/sources/dialog/staffregister_dialog.cpp similarity index 81% rename from src/sources/dialog/staffregister_dialog.cpp rename to src/rms/sources/dialog/staffregister_dialog.cpp index 184cc4ea0129af0e3267aab189a2e9783e7b22bf..1d96fd6792bb59477ae98f37cc067c60228dec3b 100644 --- a/src/sources/dialog/staffregister_dialog.cpp +++ b/src/rms/sources/dialog/staffregister_dialog.cpp @@ -1,5 +1,6 @@ -#include "src/include/dialog/staffregister_dialog.h" -#include "src/include/ui/ui_staffregister_dialog.h" +#include "dialog/staffregister_dialog.h" +#include "db/user_management.h" +#include "ui/ui_staffregister_dialog.h" staffRegister_Dialog::staffRegister_Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::staffRegister_Dialog) { @@ -21,9 +22,9 @@ void staffRegister_Dialog::on_pushButton_clicked() { QString password = ui->password_lineEdit->text(); QString rePassword = ui->rePassword_lineEdit->text(); if (password == rePassword) { - QString jurisdiction = ui->comboBox->currentText(); //权限 - UserManagement userManagerment=UserManagement(); - if (userManagerment.registerUser(name,password,jurisdiction)) { + QString jurisdiction = ui->comboBox->currentText(); //权限 + UserManagement userManagerment = UserManagement(); + if (userManagerment.registerUser(name, password, jurisdiction)) { QMessageBox::information(this, "温馨提示", "注册成功"); } else { QMessageBox::information(this, "温馨提示", "注册失败,请重新注册"); diff --git a/src/sources/dialog/stockqquery_dialog.cpp b/src/rms/sources/dialog/stockqquery_dialog.cpp similarity index 83% rename from src/sources/dialog/stockqquery_dialog.cpp rename to src/rms/sources/dialog/stockqquery_dialog.cpp index fa0be9616dda095af70be7abe2e705d8e1abeb5e..fff89d2c5a53134341576f54fd852e93e1f58c93 100644 --- a/src/sources/dialog/stockqquery_dialog.cpp +++ b/src/rms/sources/dialog/stockqquery_dialog.cpp @@ -1,5 +1,5 @@ -#include "src/include/dialog/stockqquery_dialog.h" -#include "src/include/ui/ui_stockquery_dialog.h" +#include "dialog/stockqquery_dialog.h" +#include "ui/ui_stockquery_dialog.h" StockqQuery_Dialog::StockqQuery_Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::StockqQuery_Dialog) { @@ -8,8 +8,8 @@ StockqQuery_Dialog::StockqQuery_Dialog(QWidget *parent) //初始化表格 ui->tableWidget->setSelectionBehavior( - QAbstractItemView::SelectRows); //选中整行 - ui->tableWidget->setAlternatingRowColors(true); //设置没行变一色 + QAbstractItemView::SelectRows); //选中整行 + ui->tableWidget->setAlternatingRowColors(true); //设置没行变一色 ui->tableWidget->setColumnCount(3); QStringList list; list << "商品名" @@ -29,7 +29,7 @@ StockqQuery_Dialog::StockqQuery_Dialog(QWidget *parent) //设置选中背景色 ui->tableWidget->setStyleSheet("selection-background-color:lightblue;"); ui->tableWidget->setSelectionMode( - QAbstractItemView::SingleSelection); //设置为可以选中单个 + QAbstractItemView::SingleSelection); //设置为可以选中单个 ui->tableWidget->setRowCount(2); ui->tableWidget->setItem(0, 0, new QTableWidgetItem("studentid")); ui->tableWidget->setItem(0, 1, new QTableWidgetItem("有人")); diff --git a/src/sources/dialog/varietymenu_dialog.cpp b/src/rms/sources/dialog/varietymenu_dialog.cpp similarity index 82% rename from src/sources/dialog/varietymenu_dialog.cpp rename to src/rms/sources/dialog/varietymenu_dialog.cpp index 62fd7abb1da0845a84e2d1c8b5b93d3e6cb2be11..e63533089dd25b01f3dc3090de4fae81d225f623 100644 --- a/src/sources/dialog/varietymenu_dialog.cpp +++ b/src/rms/sources/dialog/varietymenu_dialog.cpp @@ -1,5 +1,5 @@ -#include "src/include/ui/ui_varietymenu_dialog.h" -#include "src/include/dialog/varietymenu_dialog.h" +#include "dialog/varietymenu_dialog.h" +#include "ui/ui_varietymenu_dialog.h" VarietyMenuDialog::VarietyMenuDialog(QWidget *parent) : QDialog(parent), ui(new Ui::VarietyMenuDialog) { diff --git a/src/sources/main/main.cpp b/src/rms/sources/main/main.cpp similarity index 80% rename from src/sources/main/main.cpp rename to src/rms/sources/main/main.cpp index 30c2b9eedad58a3dd35a9f5b5bbf6d531c6b5bff..5346d9075a462fc022f014245b3d0e8cec38a861 100644 --- a/src/sources/main/main.cpp +++ b/src/rms/sources/main/main.cpp @@ -2,8 +2,8 @@ #include #include -#include "src/include/db/init_database.h" -#include "src/include/main/mainwindow.h" +#include "db/init_database.h" +#include "main/mainwindow.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); diff --git a/src/sources/main/mainwindow.cpp b/src/rms/sources/main/mainwindow.cpp similarity index 83% rename from src/sources/main/mainwindow.cpp rename to src/rms/sources/main/mainwindow.cpp index 20da142c4b7024a41a4177cceed0a70bb0472197..6a7ee9911ca2c4cb5542129bc66824234a48ca1d 100644 --- a/src/sources/main/mainwindow.cpp +++ b/src/rms/sources/main/mainwindow.cpp @@ -1,21 +1,21 @@ -#include "src/include/main/mainwindow.h" -#include "src/include/dialog/add_reduce_dialog.h" -#include "src/include/dialog/check_out_dialog.h" -#include "src/include/dialog/dayincomequery_dialog.h" -#include "src/include/db/day_statistics.h" -#include "src/include/dialog/foodinfo_dialog.h" -#include "src/include/ui/ui_mainwindow.h" -#include "src/include/dialog/monthincomequery_dialog.h" -#include "src/include/dialog/selectseat_dialog.h" -#include "src/include/dialog/staffregister_dialog.h" -#include "src/include/dialog/stockqquery_dialog.h" +#include "main/mainwindow.h" #include +#include "db/day_statistics.h" +#include "dialog/add_reduce_dialog.h" +#include "dialog/check_out_dialog.h" +#include "dialog/dayincomequery_dialog.h" +#include "dialog/foodinfo_dialog.h" +#include "dialog/monthincomequery_dialog.h" +#include "dialog/selectseat_dialog.h" +#include "dialog/staffregister_dialog.h" +#include "dialog/stockqquery_dialog.h" +#include "ui/ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->setWindowTitle("餐饮管理系统"); - QDesktopWidget *desktop = QApplication::desktop(); // =qApp->desktop();也可以 + QDesktopWidget *desktop = QApplication::desktop(); // =qApp->desktop();也可以 this->move((desktop->width() - this->width()) / 2, (desktop->height() - this->height()) / 2); ui->statusBar->showMessage("未登录"); @@ -57,9 +57,7 @@ void MainWindow::on_action_Login_triggered() { } void MainWindow::on_action_Quit_triggered() { - - if (true == pass) - QMessageBox::information(this, "提示", "已退出登录"); + if (true == pass) QMessageBox::information(this, "提示", "已退出登录"); pass = false; admin = false; setEnabledMenu(false); diff --git a/src/sources/ui/ui_add_reduce_dialog.cpp b/src/rms/sources/ui/ui_add_reduce_dialog.cpp similarity index 89% rename from src/sources/ui/ui_add_reduce_dialog.cpp rename to src/rms/sources/ui/ui_add_reduce_dialog.cpp index 5a21fb3ec4040b76ae8c430f26a037feeafee5bd..677420c4527da5fb5752b9d19cd7bdc616cf4e14 100644 --- a/src/sources/ui/ui_add_reduce_dialog.cpp +++ b/src/rms/sources/ui/ui_add_reduce_dialog.cpp @@ -1,4 +1,4 @@ -#include "src/include/ui/ui_add_reduce_dialog.h" +#include "ui/ui_add_reduce_dialog.h" void Ui_Add_Reduce_Dialog::setupUi(QDialog *Add_Reduce_Dialog) { if (Add_Reduce_Dialog->objectName().isEmpty()) @@ -53,15 +53,16 @@ void Ui_Add_Reduce_Dialog::setupUi(QDialog *Add_Reduce_Dialog) { retranslateUi(Add_Reduce_Dialog); QMetaObject::connectSlotsByName(Add_Reduce_Dialog); -} // setupUi +} // setupUi void Ui_Add_Reduce_Dialog::retranslateUi(QDialog *Add_Reduce_Dialog) { Add_Reduce_Dialog->setWindowTitle( QApplication::translate("Add_Reduce_Dialog", "Dialog", nullptr)); - label->setText(QApplication::translate( - "Add_Reduce_Dialog", "\351\234\200\350\246\201\346\234\215\345\212\241" - "\347\232\204\346\241\214\345\217\267:", - nullptr)); + label->setText( + QApplication::translate("Add_Reduce_Dialog", + "\351\234\200\350\246\201\346\234\215\345\212\241" + "\347\232\204\346\241\214\345\217\267:", + nullptr)); addButton->setText( QApplication::translate("Add_Reduce_Dialog", ">>", nullptr)); deleteButton->setText( @@ -70,4 +71,4 @@ void Ui_Add_Reduce_Dialog::retranslateUi(QDialog *Add_Reduce_Dialog) { "Add_Reduce_Dialog", "\347\241\256\345\256\232", nullptr)); cancelButton->setText(QApplication::translate( "Add_Reduce_Dialog", "\345\217\226\346\266\210", nullptr)); -} // retranslateUi +} // retranslateUi diff --git a/src/sources/ui/ui_check_out_dialog.cpp b/src/rms/sources/ui/ui_check_out_dialog.cpp similarity index 98% rename from src/sources/ui/ui_check_out_dialog.cpp rename to src/rms/sources/ui/ui_check_out_dialog.cpp index bb8e2786334c761650594127eb644a32ab6b691e..7f790b2f12f577c3ce3bbd73914f455fcac73db6 100644 --- a/src/sources/ui/ui_check_out_dialog.cpp +++ b/src/rms/sources/ui/ui_check_out_dialog.cpp @@ -1,4 +1,4 @@ -#include "src/include/ui/ui_check_out_dialog.h" +#include "ui/ui_check_out_dialog.h" void Ui_Check_Out_Dialog::setupUi(QDialog *Check_OutDialog) { if (Check_OutDialog->objectName().isEmpty()) @@ -97,7 +97,7 @@ void Ui_Check_Out_Dialog::setupUi(QDialog *Check_OutDialog) { retranslateUi(Check_OutDialog); QMetaObject::connectSlotsByName(Check_OutDialog); -} // setupUi +} // setupUi void Ui_Check_Out_Dialog::retranslateUi(QDialog *Check_OutDialog) { Check_OutDialog->setWindowTitle( @@ -117,4 +117,4 @@ void Ui_Check_Out_Dialog::retranslateUi(QDialog *Check_OutDialog) { "Check_OutDialog", "\347\273\223\345\270\220", nullptr)); pushButton_2->setText(QApplication::translate( "Check_OutDialog", "\351\200\200\345\207\272", nullptr)); -} // retranslateUi +} // retranslateUi diff --git a/src/sources/ui/ui_dayincomequery_dialog.cpp b/src/rms/sources/ui/ui_dayincomequery_dialog.cpp similarity index 97% rename from src/sources/ui/ui_dayincomequery_dialog.cpp rename to src/rms/sources/ui/ui_dayincomequery_dialog.cpp index fc7f51f4ee38bfaaa4a4a62808eaf3ca2d5302c4..f287b5be67d34bc38645e67a2fd464beff2ed877 100644 --- a/src/sources/ui/ui_dayincomequery_dialog.cpp +++ b/src/rms/sources/ui/ui_dayincomequery_dialog.cpp @@ -1,4 +1,4 @@ -#include "src/include/ui/ui_dayincomequery_dialog.h" +#include "ui/ui_dayincomequery_dialog.h" void Ui_DayIncomeQuery_Dialog::setupUi(QDialog *DayIncomeQuery_Dialog) { if (DayIncomeQuery_Dialog->objectName().isEmpty()) @@ -62,7 +62,7 @@ void Ui_DayIncomeQuery_Dialog::setupUi(QDialog *DayIncomeQuery_Dialog) { retranslateUi(DayIncomeQuery_Dialog); QMetaObject::connectSlotsByName(DayIncomeQuery_Dialog); -} // setupUi +} // setupUi void Ui_DayIncomeQuery_Dialog::retranslateUi(QDialog *DayIncomeQuery_Dialog) { DayIncomeQuery_Dialog->setWindowTitle( @@ -80,4 +80,4 @@ void Ui_DayIncomeQuery_Dialog::retranslateUi(QDialog *DayIncomeQuery_Dialog) { "\346\234\210", nullptr)); label_4->setText(QApplication::translate("DayIncomeQuery_Dialog", "\346\227\245", nullptr)); -} // retranslateUi +} // retranslateUi diff --git a/src/sources/ui/ui_dishescount_dialog.cpp b/src/rms/sources/ui/ui_dishescount_dialog.cpp similarity index 96% rename from src/sources/ui/ui_dishescount_dialog.cpp rename to src/rms/sources/ui/ui_dishescount_dialog.cpp index 9aadaf0138b715e6b7d0298b7f6ee0f6d38e2904..43f92b31b28847b9f4efeebeb7c85202a54deb50 100644 --- a/src/sources/ui/ui_dishescount_dialog.cpp +++ b/src/rms/sources/ui/ui_dishescount_dialog.cpp @@ -1,4 +1,4 @@ -#include "src/include/ui/ui_dishescount_dialog.h" +#include "ui/ui_dishescount_dialog.h" void Ui_DishesCount_Dialog::setupUi(QDialog *DishesCountDialog) { if (DishesCountDialog->objectName().isEmpty()) @@ -48,7 +48,7 @@ void Ui_DishesCount_Dialog::setupUi(QDialog *DishesCountDialog) { retranslateUi(DishesCountDialog); QMetaObject::connectSlotsByName(DishesCountDialog); -} // setupUi +} // setupUi void Ui_DishesCount_Dialog::retranslateUi(QDialog *DishesCountDialog) { DishesCountDialog->setWindowTitle( @@ -59,4 +59,4 @@ void Ui_DishesCount_Dialog::retranslateUi(QDialog *DishesCountDialog) { "DishesCountDialog", "\347\241\256\345\256\232", nullptr)); pushButton_2->setText(QApplication::translate( "DishesCountDialog", "\350\277\224\345\233\236", nullptr)); -} // retranslateUi +} // retranslateUi diff --git a/src/sources/ui/ui_foodinfo_dialog.cpp b/src/rms/sources/ui/ui_foodinfo_dialog.cpp similarity index 97% rename from src/sources/ui/ui_foodinfo_dialog.cpp rename to src/rms/sources/ui/ui_foodinfo_dialog.cpp index ae338eeaacb8eb7d45bf81e1ae0b21f2df8f6c96..286c59808d30ef6e6016861ca6c3f1a441f42271 100644 --- a/src/sources/ui/ui_foodinfo_dialog.cpp +++ b/src/rms/sources/ui/ui_foodinfo_dialog.cpp @@ -1,4 +1,4 @@ -#include "src/include/ui/ui_foodinfo_dialog.h" +#include "ui/ui_foodinfo_dialog.h" void Ui_FoodInfo_Dialog::setupUi(QDialog *FoodInfo_Dialog) { if (FoodInfo_Dialog->objectName().isEmpty()) @@ -78,7 +78,7 @@ void Ui_FoodInfo_Dialog::setupUi(QDialog *FoodInfo_Dialog) { retranslateUi(FoodInfo_Dialog); QMetaObject::connectSlotsByName(FoodInfo_Dialog); -} // setupUi +} // setupUi void Ui_FoodInfo_Dialog::retranslateUi(QDialog *FoodInfo_Dialog) { FoodInfo_Dialog->setWindowTitle( @@ -94,4 +94,4 @@ void Ui_FoodInfo_Dialog::retranslateUi(QDialog *FoodInfo_Dialog) { addFood_Button->setText(QApplication::translate( "FoodInfo_Dialog", "\346\267\273\345\212\240\350\217\234\345\223\201", nullptr)); -} // retranslateUi +} // retranslateUi diff --git a/src/sources/ui/ui_login_dialog.cpp b/src/rms/sources/ui/ui_login_dialog.cpp similarity index 97% rename from src/sources/ui/ui_login_dialog.cpp rename to src/rms/sources/ui/ui_login_dialog.cpp index 49216abe2a4028548889274819a04dafad1a52d3..2383a59c4320d049b2215945d480faa4b3c6fa1d 100644 --- a/src/sources/ui/ui_login_dialog.cpp +++ b/src/rms/sources/ui/ui_login_dialog.cpp @@ -1,4 +1,4 @@ -#include "src/include/ui/ui_login_dialog.h" +#include "ui/ui_login_dialog.h" void Ui_Login_Dialog::setupUi(QDialog *LoginDialog) { if (LoginDialog->objectName().isEmpty()) @@ -79,7 +79,7 @@ void Ui_Login_Dialog::setupUi(QDialog *LoginDialog) { button_Close->setIcon(closeIcon); QMetaObject::connectSlotsByName(LoginDialog); -} // setupUi +} // setupUi void Ui_Login_Dialog::retranslateUi(QDialog *LoginDialog) { LoginDialog->setWindowTitle( @@ -92,4 +92,4 @@ void Ui_Login_Dialog::retranslateUi(QDialog *LoginDialog) { "LoginDialog", "\347\231\273\345\275\225", nullptr)); button_Quit->setText(QApplication::translate( "LoginDialog", "\351\200\200\345\207\272", nullptr)); -} // retranslateUi +} // retranslateUi diff --git a/src/sources/ui/ui_mainwindow.cpp b/src/rms/sources/ui/ui_mainwindow.cpp similarity index 98% rename from src/sources/ui/ui_mainwindow.cpp rename to src/rms/sources/ui/ui_mainwindow.cpp index f03b0a3b4763e4984d69f196a6fa30bee1769b46..90c2019811ec0db5772b62304da0bb4090b85adc 100644 --- a/src/sources/ui/ui_mainwindow.cpp +++ b/src/rms/sources/ui/ui_mainwindow.cpp @@ -1,4 +1,4 @@ -#include "src/include/ui/ui_mainwindow.h" +#include "ui/ui_mainwindow.h" #include void Ui_MainWindow::setupUi(QMainWindow *MainWindow) { @@ -148,15 +148,16 @@ void Ui_MainWindow::setupUi(QMainWindow *MainWindow) { retranslateUi(MainWindow); QMetaObject::connectSlotsByName(MainWindow); -} // setupUi +} // setupUi void Ui_MainWindow::retranslateUi(QMainWindow *MainWindow) { MainWindow->setWindowTitle( QApplication::translate("MainWindow", "MainWindow", nullptr)); action_AuthorityManagement->setText(QApplication::translate( - "MainWindow", "\347\224\250\346\210\267\346\235\203\351\231\220\347\256" - "\241\347\220\206", + "MainWindow", + "\347\224\250\346\210\267\346\235\203\351\231\220\347\256" + "\241\347\220\206", nullptr)); action_Start->setText(QApplication::translate( "MainWindow", "\345\274\200\345\247\213\347\202\271\350\217\234", @@ -217,4 +218,4 @@ void Ui_MainWindow::retranslateUi(QMainWindow *MainWindow) { nullptr)); menu_Help->setTitle(QApplication::translate( "MainWindow", "\345\270\256\345\212\251", nullptr)); -} // retranslateUi +} // retranslateUi diff --git a/src/sources/ui/ui_monthincomequery_dialog.cpp b/src/rms/sources/ui/ui_monthincomequery_dialog.cpp similarity index 97% rename from src/sources/ui/ui_monthincomequery_dialog.cpp rename to src/rms/sources/ui/ui_monthincomequery_dialog.cpp index 46a6f4bc84a05b90fd72b165d7674ce60590eb82..49ed56b38ebae32669e755843f282366df7174ea 100644 --- a/src/sources/ui/ui_monthincomequery_dialog.cpp +++ b/src/rms/sources/ui/ui_monthincomequery_dialog.cpp @@ -1,4 +1,4 @@ -#include "src/include/ui/ui_monthincomequery_dialog.h" +#include "ui/ui_monthincomequery_dialog.h" void Ui_MonthIncomeQuery_Dialog::setupUi(QDialog *MonthIncomeQuery_Dialog) { if (MonthIncomeQuery_Dialog->objectName().isEmpty()) @@ -62,7 +62,7 @@ void Ui_MonthIncomeQuery_Dialog::setupUi(QDialog *MonthIncomeQuery_Dialog) { retranslateUi(MonthIncomeQuery_Dialog); QMetaObject::connectSlotsByName(MonthIncomeQuery_Dialog); -} // setupUi +} // setupUi void Ui_MonthIncomeQuery_Dialog::retranslateUi( QDialog *MonthIncomeQuery_Dialog) { @@ -80,4 +80,4 @@ void Ui_MonthIncomeQuery_Dialog::retranslateUi( "MonthIncomeQuery_Dialog", "\346\237\245\350\257\242", nullptr)); quitButton->setText(QApplication::translate( "MonthIncomeQuery_Dialog", "\351\200\200\345\207\272", nullptr)); -} // retranslateUi +} // retranslateUi diff --git a/src/sources/ui/ui_orderdishes_dialog.cpp b/src/rms/sources/ui/ui_orderdishes_dialog.cpp similarity index 98% rename from src/sources/ui/ui_orderdishes_dialog.cpp rename to src/rms/sources/ui/ui_orderdishes_dialog.cpp index 7f58641c9a669a19e18db36839ba665a552008c9..2578978c3ff388b9957133264163fefe13960a19 100644 --- a/src/sources/ui/ui_orderdishes_dialog.cpp +++ b/src/rms/sources/ui/ui_orderdishes_dialog.cpp @@ -1,4 +1,4 @@ -#include "src/include/ui/ui_orderdishes_dialog.h" +#include "ui/ui_orderdishes_dialog.h" void Ui_OrderDishes_Dialog::setupUi(QDialog *OrderDishesDialog) { if (OrderDishesDialog->objectName().isEmpty()) @@ -83,7 +83,7 @@ void Ui_OrderDishes_Dialog::setupUi(QDialog *OrderDishesDialog) { retranslateUi(OrderDishesDialog); QMetaObject::connectSlotsByName(OrderDishesDialog); -} // setupUi +} // setupUi void Ui_OrderDishes_Dialog::retranslateUi(QDialog *OrderDishesDialog) { OrderDishesDialog->setWindowTitle( @@ -101,4 +101,4 @@ void Ui_OrderDishes_Dialog::retranslateUi(QDialog *OrderDishesDialog) { label_2->setText(QApplication::translate( "OrderDishesDialog", "\345\275\223\345\211\215\346\227\245\346\234\237:", nullptr)); -} // retranslateUi +} // retranslateUi diff --git a/src/sources/ui/ui_selectseat_dialog.cpp b/src/rms/sources/ui/ui_selectseat_dialog.cpp similarity index 88% rename from src/sources/ui/ui_selectseat_dialog.cpp rename to src/rms/sources/ui/ui_selectseat_dialog.cpp index db19309978e1de9230805fe67cf0e85f8e386e6f..bd78c102fc97daba8280db95903159252f1886f4 100644 --- a/src/sources/ui/ui_selectseat_dialog.cpp +++ b/src/rms/sources/ui/ui_selectseat_dialog.cpp @@ -6,7 +6,7 @@ ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ -#include "src/include/ui/ui_selectseat_dialog.h" +#include "ui/ui_selectseat_dialog.h" void Ui_SelectSeat_Dialog::setupUi(QDialog *SelectSeat_Dialog) { if (SelectSeat_Dialog->objectName().isEmpty()) @@ -52,17 +52,18 @@ void Ui_SelectSeat_Dialog::setupUi(QDialog *SelectSeat_Dialog) { retranslateUi(SelectSeat_Dialog); QMetaObject::connectSlotsByName(SelectSeat_Dialog); -} // setupUi +} // setupUi void Ui_SelectSeat_Dialog::retranslateUi(QDialog *SelectSeat_Dialog) { SelectSeat_Dialog->setWindowTitle( QApplication::translate("SelectSeat_Dialog", "Dialog", nullptr)); - label->setText(QApplication::translate( - "SelectSeat_Dialog", "\351\241\276\345\256\242\351\200\211\346\213\251" - "\347\232\204\346\241\214\345\217\267:", - nullptr)); + label->setText( + QApplication::translate("SelectSeat_Dialog", + "\351\241\276\345\256\242\351\200\211\346\213\251" + "\347\232\204\346\241\214\345\217\267:", + nullptr)); button_Ok->setText(QApplication::translate( "SelectSeat_Dialog", "\347\241\256\345\256\232", nullptr)); button_Cancel->setText(QApplication::translate( "SelectSeat_Dialog", "\345\217\226\346\266\210", nullptr)); -} // retranslateUi +} // retranslateUi diff --git a/src/sources/ui/ui_staffregister_dialog.cpp b/src/rms/sources/ui/ui_staffregister_dialog.cpp similarity index 98% rename from src/sources/ui/ui_staffregister_dialog.cpp rename to src/rms/sources/ui/ui_staffregister_dialog.cpp index e3ac0e5a645ac06c42a3743cde81eab8a9fc3bb0..2a300fa92138837a1c7f1eeb83093d6e66103eeb 100644 --- a/src/sources/ui/ui_staffregister_dialog.cpp +++ b/src/rms/sources/ui/ui_staffregister_dialog.cpp @@ -1,4 +1,4 @@ -#include "src/include/ui/ui_staffregister_dialog.h" +#include "ui/ui_staffregister_dialog.h" void Ui_staffRegister_Dialog::setupUi(QDialog *staffRegister_Dialog) { if (staffRegister_Dialog->objectName().isEmpty()) @@ -110,7 +110,7 @@ void Ui_staffRegister_Dialog::setupUi(QDialog *staffRegister_Dialog) { retranslateUi(staffRegister_Dialog); QMetaObject::connectSlotsByName(staffRegister_Dialog); -} // setupUi +} // setupUi void Ui_staffRegister_Dialog::retranslateUi(QDialog *staffRegister_Dialog) { staffRegister_Dialog->setWindowTitle( @@ -131,4 +131,4 @@ void Ui_staffRegister_Dialog::retranslateUi(QDialog *staffRegister_Dialog) { "staffRegister_Dialog", "\351\207\215\347\275\256", nullptr)); cancel_pushButton->setText(QApplication::translate( "staffRegister_Dialog", "\345\217\226\346\266\210", nullptr)); -} // retranslateUi +} // retranslateUi diff --git a/src/sources/ui/ui_stockquery_dialog.cpp b/src/rms/sources/ui/ui_stockquery_dialog.cpp similarity index 88% rename from src/sources/ui/ui_stockquery_dialog.cpp rename to src/rms/sources/ui/ui_stockquery_dialog.cpp index dc9c99971c9083155ee696aa09e8ab8f15d6c514..b38a748d06eef8d1e2341e321d95a47de40b3b78 100644 --- a/src/sources/ui/ui_stockquery_dialog.cpp +++ b/src/rms/sources/ui/ui_stockquery_dialog.cpp @@ -1,4 +1,4 @@ -#include "src/include/ui/ui_stockquery_dialog.h" +#include "ui/ui_stockquery_dialog.h" void Ui_StockqQuery_Dialog::setupUi(QDialog *StockqQuery_Dialog) { if (StockqQuery_Dialog->objectName().isEmpty()) @@ -49,17 +49,18 @@ void Ui_StockqQuery_Dialog::setupUi(QDialog *StockqQuery_Dialog) { retranslateUi(StockqQuery_Dialog); QMetaObject::connectSlotsByName(StockqQuery_Dialog); -} // setupUi +} // setupUi void Ui_StockqQuery_Dialog::retranslateUi(QDialog *StockqQuery_Dialog) { StockqQuery_Dialog->setWindowTitle( QApplication::translate("StockqQuery_Dialog", "Dialog", nullptr)); - label->setText(QApplication::translate( - "StockqQuery_Dialog", "\350\257\267\351\200\211\346\213\251\345\271\264" - "\346\234\210\346\227\245:", - nullptr)); + label->setText( + QApplication::translate("StockqQuery_Dialog", + "\350\257\267\351\200\211\346\213\251\345\271\264" + "\346\234\210\346\227\245:", + nullptr)); queryButton->setText(QApplication::translate( "StockqQuery_Dialog", "\346\237\245\350\257\242", nullptr)); quit_Button->setText(QApplication::translate( "StockqQuery_Dialog", "\351\200\200\345\207\272", nullptr)); -} // retranslateUi +} // retranslateUi diff --git a/src/sources/ui/ui_varietymenu_dialog.cpp b/src/rms/sources/ui/ui_varietymenu_dialog.cpp similarity index 97% rename from src/sources/ui/ui_varietymenu_dialog.cpp rename to src/rms/sources/ui/ui_varietymenu_dialog.cpp index 2a666b4f9aa858263513f31e9ed8b7a18f435882..9b0697728da48cc13f1db0df0fe82e7d2c50a602 100644 --- a/src/sources/ui/ui_varietymenu_dialog.cpp +++ b/src/rms/sources/ui/ui_varietymenu_dialog.cpp @@ -1,4 +1,4 @@ -#include "src/include/ui/ui_varietymenu_dialog.h" +#include "ui/ui_varietymenu_dialog.h" void Ui_VarietyMenu_Dialog::setupUi(QDialog *VarietyMenuDialog) { if (VarietyMenuDialog->objectName().isEmpty()) @@ -77,7 +77,7 @@ void Ui_VarietyMenu_Dialog::setupUi(QDialog *VarietyMenuDialog) { retranslateUi(VarietyMenuDialog); QMetaObject::connectSlotsByName(VarietyMenuDialog); -} // setupUi +} // setupUi void Ui_VarietyMenu_Dialog::retranslateUi(QDialog *VarietyMenuDialog) { VarietyMenuDialog->setWindowTitle( @@ -96,4 +96,4 @@ void Ui_VarietyMenu_Dialog::retranslateUi(QDialog *VarietyMenuDialog) { "VarietyMenuDialog", "\345\210\240\351\231\244", nullptr)); quit_Button->setText(QApplication::translate( "VarietyMenuDialog", "\351\200\200\345\207\272", nullptr)); -} // retranslateUi +} // retranslateUi