forked from wiglot/LogView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.cpp
executable file
·67 lines (58 loc) · 1.63 KB
/
logger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// C++ Implementation: logpool
//
// Description:
//
//
// Author: Wagner de Melo Reck,,, <wagner@wiglotron>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "logger.h"
#include <QFile>
#include <QTextStream>
#include <QString>
namespace Logger {
LogPool * LogPool::self = 0;
LogFile::LogFile(QString fileName){
file = new QFile(fileName);
if (!file->open(QIODevice::WriteOnly | QIODevice::Text))
throw QString("Can't open the file"+fileName);
textStream = new QTextStream(file);
_saveAtEach = 0;
_stored = _saveAtEach;
_actual = LogPool::size();
}
void LogFile::saveAtEach(int value){
_saveAtEach = value;
}
LogFile::~LogFile(){
file->close();
delete textStream;
delete file;
}
void LogFile::appendLog(LogMessage* log){
LogMessage* retrieved;
int i;
if (_stored == 0){
for (i = 0 ; i < _saveAtEach && _actual < LogPool::size()-1; i++, _actual++){
retrieved = LogPool::getLog(_actual);
writeLog(retrieved);
}
writeLog(log);
file->flush();
_stored = _saveAtEach;
}else{
--_stored;
}
}
void LogFile::writeLog(LogMessage* log){
switch(log->type()){
case Logger::WARNING : *textStream << "Warning: "; break;
case Logger::FATAL : *textStream << "FATAL : "; break;
default : *textStream << "Log : ";
}
*textStream << log->message() << "\n";
}
}