Files
QsLog
YACReader
YACReaderLibrary
comic_vine
db
qml
server
controllers
lib
bfHttpServer
bfLogging
bfLogging.pri
dualfilelogger.cpp
dualfilelogger.h
filelogger.cpp
filelogger.h
logger.cpp
logger.h
logmessage.cpp
logmessage.h
bfTemplateEngine
documentcache.h
requestmapper.cpp
requestmapper.h
server.pri
startup.cpp
startup.h
static.cpp
static.h
YACReaderLibrary.icns
YACReaderLibrary.pro
add_label_dialog.cpp
add_label_dialog.h
add_library_dialog.cpp
add_library_dialog.h
bundle_creator.cpp
bundle_creator.h
classic_comics_view.cpp
classic_comics_view.h
comic_files_manager.cpp
comic_files_manager.h
comic_flow.cpp
comic_flow.h
comic_flow_widget.cpp
comic_flow_widget.h
comics_remover.cpp
comics_remover.h
comics_view.cpp
comics_view.h
comics_view_transition.cpp
comics_view_transition.h
create_library_dialog.cpp
create_library_dialog.h
db_helper.cpp
db_helper.h
empty_container_info.cpp
empty_container_info.h
empty_folder_widget.cpp
empty_folder_widget.h
empty_label_widget.cpp
empty_label_widget.h
empty_reading_list_widget.cpp
empty_reading_list_widget.h
empty_special_list.cpp
empty_special_list.h
export_comics_info_dialog.cpp
export_comics_info_dialog.h
export_library_dialog.cpp
export_library_dialog.h
files.qrc
grid_comics_view.cpp
grid_comics_view.h
icon.ico
icon.rc
icon2.ico
icon3.ico
images.qrc
images_osx.qrc
images_win.qrc
import_comics_info_dialog.cpp
import_comics_info_dialog.h
import_library_dialog.cpp
import_library_dialog.h
import_widget.cpp
import_widget.h
library_creator.cpp
library_creator.h
library_window.cpp
library_window.h
main.cpp
no_libraries_widget.cpp
no_libraries_widget.h
no_search_results_widget.cpp
no_search_results_widget.h
options_dialog.cpp
options_dialog.h
package_manager.cpp
package_manager.h
properties_dialog.cpp
properties_dialog.h
qml.qrc
qml_osx.qrc
qml_win.qrc
rename_library_dialog.cpp
rename_library_dialog.h
server_config_dialog.cpp
server_config_dialog.h
yacreader_folders_view.cpp
yacreader_folders_view.h
yacreader_history_controller.cpp
yacreader_history_controller.h
yacreader_libraries.cpp
yacreader_libraries.h
yacreader_local_server.cpp
yacreader_local_server.h
yacreader_main_toolbar.cpp
yacreader_main_toolbar.h
yacreader_navigation_controller.cpp
yacreader_navigation_controller.h
yacreader_reading_lists_view.cpp
yacreader_reading_lists_view.h
yacreaderlibrary_de.ts
yacreaderlibrary_es.qm
yacreaderlibrary_es.ts
yacreaderlibrary_fr.ts
yacreaderlibrary_nl.ts
yacreaderlibrary_pt.ts
yacreaderlibrary_ru.ts
yacreaderlibrary_source.ts
yacreaderlibrary_tr.ts
common
compressed_archive
custom_widgets
dependencies
files
images
release
shortcuts_management
tests
CHANGELOG.txt
COPYING.txt
INSTALL.txt
README.txt
YACReader.1
YACReader.desktop
YACReader.pro
YACReaderLibrary.1
YACReaderLibrary.desktop
background.png
cleanOSX.sh
compileOSX.sh
config.pri
create-dmg
generateVS2010Projects.bat
icon.icns
mktarball.sh
releaseOSX.sh
yacreader/YACReaderLibrary/server/lib/bfLogging/filelogger.h
Luis Ángel San Martín 65f8be899f merged
2015-05-05 12:45:46 +02:00

123 lines
3.9 KiB
C++

/**
@file
@author Stefan Frings
*/
#ifndef FILELOGGER_H
#define FILELOGGER_H
#include <QtGlobal>
#include <QSettings>
#include <QFile>
#include <QMutex>
#include <QBasicTimer>
#include "logger.h"
/**
Logger that uses a text file for output. Settings are read from a
config file using a QSettings object. Config settings can be changed at runtime.
<p>
Example for the configuration settings:
<code><pre>
fileName=logs/QtWebApp.log
maxSize=1000000
maxBackups=2
minLevel=0
msgformat={timestamp} {typeNr} {type} thread={thread}: {msg}
timestampFormat=dd.MM.yyyy hh:mm:ss.zzz
bufferSize=0
</pre></code>
- fileName is the name of the log file, relative to the directory of the settings file.
In case of windows, if the settings are in the registry, the path is relative to the current
working directory.
- maxSize is the maximum size of that file in bytes. The file will be backed up and
replaced by a new file if it becomes larger than this limit. Please note that
the actual file size may become a little bit larger than this limit. Default is 0=unlimited.
- maxBackups defines the number of backup files to keep. Default is 0=unlimited.
- minLevel defines the minimum type of messages that are written (together with buffered messages) into the file. Defaults is 0=debug.
- msgFormat defines the decoration of log messages, see LogMessage class. Default is "{timestamp} {type} {msg}".
- timestampFormat defines the format of timestamps, see QDateTime::toString(). Default is "yyyy-MM-dd hh:mm:ss.zzz".
- bufferSize defines the size of the buffer. Default is 0=disabled.
@see set() describes how to set logger variables
@see LogMessage for a description of the message decoration.
@see Logger for a descrition of the buffer.
*/
class FileLogger : public Logger {
Q_OBJECT
Q_DISABLE_COPY(FileLogger)
public:
/**
Constructor.
@param settings Configuration settings, usually stored in an INI file. Must not be 0.
Settings are read from the current group, so the caller must have called settings->beginGroup().
Because the group must not change during runtime, it is recommended to provide a
separate QSettings instance to the logger that is not used by other parts of the program.
@param refreshInterval Interval of checking for changed config settings in msec, or 0=disabled
@param parent Parent object
*/
FileLogger(QSettings* settings, const int refreshInterval=10000, QObject* parent = 0);
/**
Destructor. Closes the file.
*/
virtual ~FileLogger();
/** Write a message to the log file */
virtual void write(const LogMessage* logMessage);
protected:
/**
Handler for timer events.
Refreshes config settings or synchronizes I/O buffer, depending on the event.
This method is thread-safe.
@param event used to distinguish between the two timers.
*/
void timerEvent(QTimerEvent* event);
private:
/** Configured name of the log file */
QString fileName;
/** Configured maximum size of the file in bytes, or 0=unlimited */
long maxSize;
/** Configured maximum number of backup files, or 0=unlimited */
int maxBackups;
/** Pointer to the configuration settings */
QSettings* settings;
/** Output file, or 0=disabled */
QFile* file;
/** Timer for refreshing configuration settings */
QBasicTimer refreshTimer;
/** Timer for flushing the file I/O buffer */
QBasicTimer flushTimer;
/** Open the output file */
void open();
/** Close the output file */
void close();
/** Rotate files and delete some backups if there are too many */
void rotate();
/**
Refreshes the configuration settings.
This method is thread-safe.
*/
void refreshSettings();
};
#endif // FILELOGGER_H