1
/***************************************************************************
2
* Copyright (C) 2005 by Nicolas Ternisien *
3
* nicolas.ternisien@gmail.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
24
#include "ksystemlogConfig.h"
25
#include "systemReader.h"
26
#include "xorgReader.h"
27
#include "cronReader.h"
28
#include "acpidReader.h"
30
#include "cupsReader.h"
31
#include "cupsAccessReader.h"
33
#include "apacheReader.h"
34
#include "apacheAccessReader.h"
36
#include "sambaReader.h"
38
#include "readerFactory.h"
40
KURL ReaderFactory::lastOpenedURL;
42
Reader* ReaderFactory::createReader(LogMode* logMode) {
45
* Using System Mode in the current view
47
if (logMode==Globals::systemMode) {
48
Reader* reader=new SystemReader(NULL, "system_reader");
53
* Using Boot Mode in the current view
55
else if (logMode==Globals::bootMode) {
56
Reader* reader=new SystemReader(NULL, "boot_reader");
61
* Using Authentication Mode in the current view
63
else if (logMode==Globals::authenticationMode) {
64
Reader* reader=new SystemReader(NULL, "authentication_reader");
69
* Using Kernel Mode in the current view
71
else if (logMode==Globals::kernelMode) {
72
Reader* reader=new SystemReader(NULL, "kernel_reader");
77
* Using Daemon Mode in the current view
79
else if (logMode==Globals::daemonMode) {
80
Reader* reader=new SystemReader(NULL, "daemon_reader");
85
* Using Cron Mode in the current view
87
else if (logMode==Globals::cronMode) {
88
Reader* reader=new CronReader(NULL, "cron_reader");
93
* Using Cron Mode in the current view
95
else if (logMode==Globals::xorgMode) {
96
Reader* reader=new XorgReader(NULL, "xorg_reader");
102
* Using ACPID Mode in the current view
104
else if (logMode==Globals::acpidMode) {
105
Reader* reader=new AcpidReader(NULL, "acpid_reader");
110
* Using Cups Mode in the current view
112
else if (logMode==Globals::cupsMode) {
113
Reader* reader=new CupsReader(NULL, "cups_reader");
118
* Using Cups Access Mode in the current view
120
else if (logMode==Globals::cupsAccessMode) {
121
Reader* reader=new CupsAccessReader(NULL, "cups_access_reader");
126
* Using Apache Mode in the current view
128
else if (logMode==Globals::apacheMode) {
129
Reader* reader=new ApacheReader(NULL, "apache_reader");
134
* Using Apache Access Mode in the current view
136
else if (logMode==Globals::apacheAccessMode) {
137
Reader* reader=new ApacheAccessReader(NULL, "apache_access_reader");
142
* Using Postfix Mode in the current view
144
else if (logMode==Globals::postfixMode) {
145
Reader* reader=new SystemReader(NULL, "postfix_reader");
150
* Using Samba Mode in the current view
152
else if (logMode==Globals::sambaMode) {
153
Reader* reader=new SambaReader(NULL, "samba_reader");
158
* Using Opening Mode in the current view
160
else if (logMode==Globals::openingMode) {
161
//TODO For the moment, SystemReader is always used to parse file.
162
// Implement a test case for each Reader to know who is the better to read the file
163
Reader* reader=new SystemReader(NULL, "opening_reader");
167
kdDebug() << "Error : LogMode not found : returns NULL Reader" << endl;
172
LogFiles* ReaderFactory::createLogFiles(LogMode* logMode) {
175
* Using System Mode in the current view
177
if (logMode==Globals::systemMode) {
178
//Give the log file list to the reader
179
LogFiles* list=ReaderFactory::getSystemLogFiles();
184
* Using Boot Mode in the current view
186
else if (logMode==Globals::bootMode) {
187
//Give the log file list to the reader
188
LogFile* file=ReaderFactory::getBootLogFile();
189
LogFiles* list=new LogFiles();
195
* Using Authentication Mode in the current view
197
else if (logMode==Globals::authenticationMode) {
198
//Give the log file list to the reader
199
LogFile* file=ReaderFactory::getAuthenticationLogFile();
201
LogFiles* list=new LogFiles();
207
* Using Kernel Mode in the current view
209
else if (logMode==Globals::kernelMode) {
210
//Give the log file list to the reader
211
LogFiles* list=ReaderFactory::getKernelLogFiles();
216
* Using Daemon Mode in the current view
218
else if (logMode==Globals::daemonMode) {
219
//Give the log file list to the reader
220
LogFiles* list=ReaderFactory::getDaemonLogFiles();
225
* Using Cron Mode in the current view
227
else if (logMode==Globals::cronMode) {
228
//Give the log file list to the reader
229
LogFiles* list=ReaderFactory::getCronLogFiles();
234
* Using Cron Mode in the current view
236
else if (logMode==Globals::xorgMode) {
237
//Give the log file list to the reader
238
LogFiles* list=ReaderFactory::getXorgLogFiles();
244
* Using ACPID Mode in the current view
246
else if (logMode==Globals::acpidMode) {
247
//Give the log file list to the reader
248
LogFiles* list=ReaderFactory::getAcpidLogFiles();
254
* Using Cups Mode in the current view
256
else if (logMode==Globals::cupsMode) {
257
//Give the log file list to the reader
258
LogFiles* list=ReaderFactory::getCupsLogFiles();
263
* Using Cups Access Mode in the current view
265
else if (logMode==Globals::cupsAccessMode) {
266
//Give the log file list to the reader
267
LogFiles* list=ReaderFactory::getCupsAccessLogFiles();
273
* Using Apache Mode in the current view
275
else if (logMode==Globals::apacheMode) {
276
//Give the log file list to the reader
277
LogFiles* list=ReaderFactory::getApacheLogFiles();
282
* Using Apache Access Mode in the current view
284
else if (logMode==Globals::apacheAccessMode) {
285
//Give the log file list to the reader
286
LogFiles* list=ReaderFactory::getApacheAccessLogFiles();
292
* Using Postfix Mode in the current view
294
else if (logMode==Globals::postfixMode) {
295
//Give the log file list to the reader
296
LogFiles* list=ReaderFactory::getPostfixLogFiles();
301
* Using Samba Mode in the current view
303
else if (logMode==Globals::sambaMode) {
304
//Give the log file list to the reader
305
LogFiles* list=ReaderFactory::getSambaLogFiles();
310
* Using Opening Mode in the current view
312
else if (logMode==Globals::openingMode) {
313
//Give the file to open to the reader
315
//A little hack... ;-) (what an oriented-object solution !)
316
LogFile* logFile=new LogFile(lastOpenedURL, Globals::informationLogLevel);
318
LogFiles* list=new LogFiles();
319
list->append(logFile);
323
kdDebug() << "Error : LogFiles not found : returns NULL Reader" << endl;
332
LogFile* ReaderFactory::getGenericLogFile(QString& file) {
334
LogLevel* level=Globals::informationLogLevel;
337
if (!url.isValid()) {
338
kdDebug() << i18n("URL '%1' is not valid, skipping this URL.").arg(url.path()) << endl;
342
LogFile* logFile=new LogFile(url, level);
346
LogFiles* ReaderFactory::getGenericLogFiles(QStringList& stringList, QValueList<int>& valueList) {
348
LogFiles* logFiles=new LogFiles();
350
if (stringList.size() != valueList.size()) {
351
kdDebug() << i18n("The two arrays size are different, skipping the reading of log files.") << endl;
359
QStringList::Iterator itString=stringList.begin();
360
QValueList<int>::Iterator itInt=valueList.begin();
362
while(itString!=stringList.end()) {
363
if (*itInt>=0 && *itInt<(int) Globals::logLevels.count())
364
level=Globals::logLevels.at(*itInt);
366
level=Globals::informationLogLevel;
369
if (!url.isValid()) {
370
kdDebug() << i18n("URL '%1' is not valid, skipping this URL.").arg(url.path()) << endl;
376
logFile=new LogFile(url, level);
377
logFiles->push_back(logFile);
387
LogFiles* ReaderFactory::getNoModeLogFiles(QStringList& stringList) {
389
LogFiles* logFiles=new LogFiles();
393
//Default level used for No Mode logs
394
LogLevel* level=Globals::noneLogLevel;
396
QStringList::Iterator it;
397
for(it=stringList.begin(); it!=stringList.end(); it++) {
400
if (!url.isValid()) {
401
kdDebug() << i18n("URL '%1' is not valid, skipping this URL.").arg(url.path()) << endl;
405
logFile=new LogFile(url, level);
406
logFiles->push_back(logFile);
413
LogFile* ReaderFactory::getBootLogFile() {
414
QString file=KSystemLogConfig::bootPath();
415
return(getGenericLogFile(file));
418
LogFile* ReaderFactory::getAuthenticationLogFile() {
419
QString file=KSystemLogConfig::authenticationPath();
420
return(getGenericLogFile(file));
423
LogFiles* ReaderFactory::getSystemLogFiles() {
424
QStringList files=KSystemLogConfig::systemPaths();
425
QValueList<int> levels=KSystemLogConfig::systemLevels();
426
return(ReaderFactory::getGenericLogFiles(files, levels));
429
LogFiles* ReaderFactory::getAcpidLogFiles() {
430
QStringList files=KSystemLogConfig::acpidPaths();
432
return(getNoModeLogFiles(files));
435
LogFiles* ReaderFactory::getKernelLogFiles() {
436
QStringList files=KSystemLogConfig::kernelPaths();
437
QValueList<int> levels=KSystemLogConfig::kernelLevels();
438
return(ReaderFactory::getGenericLogFiles(files, levels));
441
LogFiles* ReaderFactory::getDaemonLogFiles() {
442
QStringList files=KSystemLogConfig::daemonPaths();
443
QValueList<int> levels=KSystemLogConfig::daemonLevels();
444
return(ReaderFactory::getGenericLogFiles(files, levels));
447
LogFiles* ReaderFactory::getCronLogFiles() {
448
QStringList files=KSystemLogConfig::cronPaths();
449
QValueList<int> levels=KSystemLogConfig::cronLevels();
450
return(ReaderFactory::getGenericLogFiles(files, levels));
454
LogFiles* ReaderFactory::getXorgLogFiles() {
455
QStringList stringList=KSystemLogConfig::xorgPaths();
456
return(getNoModeLogFiles(stringList));
459
LogFiles* ReaderFactory::getCupsLogFiles() {
460
QStringList stringList=KSystemLogConfig::cupsPaths();
461
return(getNoModeLogFiles(stringList));
464
LogFiles* ReaderFactory::getCupsAccessLogFiles() {
465
QStringList stringList=KSystemLogConfig::cupsAccessPaths();
466
return(getNoModeLogFiles(stringList));
469
LogFiles* ReaderFactory::getApacheLogFiles() {
470
QStringList stringList=KSystemLogConfig::apachePaths();
471
return(getNoModeLogFiles(stringList));
474
LogFiles* ReaderFactory::getApacheAccessLogFiles() {
475
QStringList stringList=KSystemLogConfig::apacheAccessPaths();
476
return(getNoModeLogFiles(stringList));
479
LogFiles* ReaderFactory::getPostfixLogFiles() {
480
QStringList files=KSystemLogConfig::postfixPaths();
481
QValueList<int> levels=KSystemLogConfig::postfixLevels();
482
return(ReaderFactory::getGenericLogFiles(files, levels));
485
LogFiles* ReaderFactory::getSambaLogFiles() {
486
QStringList stringList=KSystemLogConfig::sambaPaths();
487
return(getNoModeLogFiles(stringList));