-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LIST OF CHANGES ON THIS COMMIT: - Changed the internal application configuration system to use the standard QSettings from Qt (instead of a cfg file an ini file) - Move some of the syntax to C++ 11 - Used smart pointers where necessary/recommended - Fixed some mem leaks around the code - Enhanced the abstraction of the architecture, removed some unecessary classes added some necessary ones. - Corrected the function that searches for the configuration file (using proper Qt syntax QDir, iterators, etc) - Corrected the XML output file to properly close the XML structure - Corrected some errors on the file handling of the log, and cleanup routines - Created the JSON output file format - Created the SIGNAL/SLOT (Qt) version of an output - SignalOutput - Changed the constants to an proper global include file to easy application config and update - Added extra documentation to the source code - Added a test project to the qlogger project - Changed the qlogger project to a proper static lib project
- Loading branch information
Showing
38 changed files
with
2,659 additions
and
1,401 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* QLogger - A tiny Qt logging framework. | ||
* | ||
* MIT License | ||
* Copyright (c) 2013 sandro fadiga | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software | ||
* is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies | ||
* or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE | ||
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
#include "jsonoutput.h" | ||
|
||
namespace qlogger | ||
{ | ||
|
||
JSONOutput::JSONOutput(Configuration *cfg) : PlainTextOutput (cfg) | ||
{ | ||
this->configuration->setFileNameMask(JSON_FILE_NAME_MASK); | ||
} | ||
|
||
JSONOutput::~JSONOutput() | ||
{ | ||
if(!outputFile.isNull() && outputFile->isOpen()) | ||
{ | ||
// end current json file. | ||
close(); | ||
} | ||
PlainTextOutput::close(); | ||
} | ||
|
||
void JSONOutput::close() | ||
{ | ||
if(!outputFile.isNull()) | ||
{ | ||
// end current json file. | ||
jsonCurrentLog[JSON_LOGS] = jsonCurrentList; | ||
|
||
QJsonDocument jsonDoc(jsonCurrentLog); | ||
outputFile->write(jsonDoc.toJson()); | ||
// release the file | ||
outputFile->close(); | ||
// clean the json objects | ||
jsonCurrentLog.empty(); | ||
jsonCurrentList.empty(); | ||
} | ||
} | ||
|
||
void JSONOutput::write(const QString message, const QString owner, | ||
const Level lvl, const QDateTime timestamp, | ||
const QString functionName, const int lineNumber) | ||
{ | ||
|
||
if(!outputFile.isNull() | ||
&& outputFile->isOpen() | ||
&& (outputFile->size() > (configuration->getFileMaxSizeInKb() * 1024))) | ||
{ | ||
close(); | ||
} | ||
|
||
if(outputFile.isNull() //if there is no file | ||
|| !outputFile->isOpen() // or the file is not opened for writing | ||
|| (outputFile->size() > (configuration->getFileMaxSizeInKb() * 1024))) // or the file is already at max size | ||
{ | ||
createNextFile(); // create a new file | ||
} | ||
|
||
QJsonObject json; | ||
json[JSON_LINE] = lineNumber; | ||
json[JSON_FUNCTION] = functionName; | ||
json[JSON_DATE_TIME] = timestamp.toString(configuration->getTimestampFormat()); | ||
json[JSON_LEVEL] = levelToString(lvl); | ||
json[JSON_MESSAGE] = message; | ||
json[JSON_OWNER] = owner; | ||
jsonCurrentList.append(json); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* QLogger - A tiny Qt logging framework. | ||
* | ||
* MIT License | ||
* Copyright (c) 2013 sandro fadiga | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software | ||
* is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies | ||
* or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE | ||
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
#ifndef JSONOUTPUT_H | ||
#define JSONOUTPUT_H | ||
|
||
#include "textoutput.h" | ||
#include <QDateTime> | ||
|
||
#include <QJsonDocument> | ||
#include <QJsonObject> | ||
#include <QJsonArray> | ||
|
||
namespace qlogger { | ||
|
||
//! | ||
//! \brief The JSONOutput class - saves a text file with a standard json format with the log information | ||
//! | ||
class JSONOutput : public PlainTextOutput | ||
{ | ||
|
||
public: | ||
//! | ||
//! \brief JSONOutput | ||
//! \param cfg | ||
//! | ||
JSONOutput(Configuration* cfg); | ||
JSONOutput() = delete; | ||
//! | ||
~JSONOutput(); | ||
|
||
// Output interface | ||
public: | ||
//! | ||
//! \brief write | ||
//! \param message | ||
//! \param owner | ||
//! \param lvl | ||
//! \param timestamp | ||
//! \param functionName | ||
//! \param lineNumber | ||
//! | ||
void write(const QString message, const QString owner, | ||
const Level lvl, const QDateTime timestamp, | ||
const QString functionName, const int lineNumber); | ||
// Output interface | ||
//! | ||
//! \brief close | ||
//! | ||
void close(); | ||
|
||
private: | ||
//! | ||
//! \brief jsonCurrentLog | ||
//! | ||
QJsonObject jsonCurrentLog; | ||
//! | ||
//! \brief jsonCurrentList | ||
//! | ||
QJsonArray jsonCurrentList; | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif // JSONOUTPUT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* QLogger - A tiny Qt logging framework. | ||
* | ||
* MIT License | ||
* Copyright (c) 2013 sandro fadiga | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software | ||
* is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies | ||
* or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE | ||
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
#include "output.h" | ||
|
||
namespace qlogger | ||
{ | ||
|
||
Output::Output(Configuration* conf) : configuration(QSharedPointer<Configuration>(conf)) {} | ||
|
||
QSharedPointer<Configuration> Output::getConfiguration() const | ||
{ | ||
return configuration; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* QLogger - A tiny Qt logging framework. | ||
* | ||
* MIT License | ||
* Copyright (c) 2013 sandro fadiga | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software | ||
* is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies | ||
* or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE | ||
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
#include "signaloutput.h" | ||
|
||
#include <QDateTime> | ||
|
||
namespace qlogger | ||
{ | ||
|
||
|
||
SignalOutput::SignalOutput(Configuration *cfg) : Output(cfg) | ||
{ | ||
} | ||
|
||
void SignalOutput::write(const QString message, const QString owner, const Level lvl, | ||
const QDateTime timestamp, const QString functionName, | ||
const int lineNumber) | ||
{ | ||
|
||
QString logtext = formatLogText(configuration->getLogTextMask(), | ||
message, owner, levelToString(lvl), | ||
timestamp.toString(configuration->getTimestampFormat()), | ||
functionName, lineNumber); | ||
emit qlogger(logtext); | ||
|
||
} | ||
|
||
void SignalOutput::close() | ||
{ | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* QLogger - A tiny Qt logging framework. | ||
* | ||
* MIT License | ||
* Copyright (c) 2013 sandro fadiga | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software | ||
* is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies | ||
* or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE | ||
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
#ifndef SIGNALOUTPUT_H | ||
#define SIGNALOUTPUT_H | ||
|
||
#include <QObject> | ||
|
||
#include "consoleoutput.h" | ||
|
||
namespace qlogger | ||
{ | ||
|
||
//! | ||
//! \brief The SignalOutput class - An output class tha 'writes' to a SLOT, this class is also a QObject so | ||
//! it can emit a SIGNAL when a log is written | ||
//! | ||
class SignalOutput : public QObject, public Output | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
//! | ||
//! \brief SignalOutput | ||
//! \param cfg | ||
//! | ||
SignalOutput(Configuration *cfg); | ||
SignalOutput() = delete; | ||
//! | ||
~SignalOutput() = default; | ||
|
||
// Output interface | ||
public: | ||
//! | ||
//! \brief write | ||
//! \param message | ||
//! \param owner | ||
//! \param lvl | ||
//! \param timestamp | ||
//! \param functionName | ||
//! \param lineNumber | ||
//! | ||
void write(const QString message, const QString owner, const Level lvl, | ||
const QDateTime timestamp, const QString functionName, const int lineNumber); | ||
|
||
//! | ||
//! \brief close | ||
//! | ||
void close(); | ||
|
||
signals: | ||
//! | ||
//! \brief qlogger - the signal emmited when 'write' is called | ||
//! \param logtext - the output text written by this log to the SLOT | ||
//! | ||
void qlogger(QString logtext); | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif // SIGNALOUTPUT_H |
Oops, something went wrong.