KSystemLog – system log viewer tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
4.9KB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Nicolas Ternisien *
  3. * nicolas.ternisien@gmail.com *
  4. * *
  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. *
  9. * *
  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. *
  14. * *
  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. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
  19. ***************************************************************************/
  20. #include <tdelocale.h>
  21. #include <tdemessagebox.h>
  22. #include "parsingHelper.h"
  23. #include "apacheReader.h"
  24. ApacheReader::ApacheReader(TQObject *parent, const char *name) :
  25. DefaultReader(parent, name)
  26. {
  27. initializeTypeLevels();
  28. }
  29. ApacheReader::~ApacheReader() {
  30. }
  31. void ApacheReader::initColumns(LogViewColumns* columns) {
  32. columns->append(new LogViewColumn(i18n("Date"), true, false));
  33. columns->append(new LogViewColumn(i18n("Client"), true, false));
  34. columns->append(new LogViewColumn(i18n("Message"), true, false));
  35. }
  36. LogLine* ApacheReader::parseMessage(TQString& logLine, LogFile* logFile) {
  37. /*
  38. * Log line examples :
  39. * [Wed May 18 22:16:02 2005] [error] [client 127.0.0.1] File does not exist: /var/www/html/ksystemlog/screenshots/small/kernel-view.png, referer: http://localhost.localdomain/ksystemlog/screenshots.php
  40. * [Wed May 18 22:16:02 2005] [error] [client 127.0.0.1] File does not exist: /var/www/html/ksystemlog/screenshots/small/system-filter.png, referer: http://localhost.localdomain/ksystemlog/screenshots.php
  41. * [Thu May 19 18:00:19 2005] [notice] mod_jk2.post_config() first invocation
  42. * [Thu May 19 18:00:19 2005] [notice] Digest: generating secret for digest authentication ...
  43. * [client 127.0.0.1] PHP Parse error: parse error, unexpected T_PRIVATE, expecting T_STRING in /mnt/boulot/web/annivernet/src/fonctions/formulaire.inc.php on line 25
  44. */
  45. TQDate date;
  46. TQTime time;
  47. TQString level;
  48. //Temporary variable
  49. int squareBracket;
  50. //Special case which sometimes happens
  51. if (logLine.find("[client")==0) {
  52. date=TQDate::currentDate();
  53. time=TQTime::currentTime();
  54. level="notice";
  55. }
  56. else {
  57. //The Date
  58. int dateBegin=logLine.find("[");
  59. int dateEnd=logLine.find("]");
  60. TQString type;
  61. TQString message;
  62. TQString strDate=logLine.mid(dateBegin+1, dateEnd-dateBegin-1);
  63. TQString month=strDate.mid(4, 3);
  64. TQString day=strDate.mid(8, 2);
  65. TQString hour=strDate.mid(11, 2);
  66. TQString min=strDate.mid(14, 2);
  67. TQString sec=strDate.mid(17, 2);
  68. TQString year=strDate.mid(20, 4);
  69. date=TQDate(year.toInt(), ParsingHelper::parseMonthNumber(month), day.toInt());
  70. time=TQTime(hour.toInt(), min.toInt(), sec.toInt());
  71. logLine=logLine.remove(0, dateEnd+3);
  72. //The log level
  73. squareBracket=logLine.find("]");
  74. level=logLine.left(squareBracket);
  75. logLine=logLine.remove(0, squareBracket+2);
  76. }
  77. //The client
  78. int beginSquareBracket=logLine.find("[client");
  79. squareBracket=logLine.find("]");
  80. TQString client;
  81. if (beginSquareBracket==-1 || squareBracket==-1) {
  82. client="";
  83. }
  84. else {
  85. client=logLine.mid(8, squareBracket-8); //8=strlen("[client ")
  86. logLine=logLine.remove(0, squareBracket+2);
  87. }
  88. TQStringList list;
  89. list.push_back(client);
  90. list.push_back(logLine);
  91. TQString filePath=logFile->url.path();
  92. LogLine* line=new LogLine(date, time, list, filePath, getTypeLevel(level), Globals::apacheMode->id);
  93. return(line);
  94. }
  95. void ApacheReader::initializeTypeLevels() {
  96. mapTypeLevels["notice"]=Globals::informationLogLevel;
  97. mapTypeLevels["warn"]=Globals::warningLogLevel;
  98. mapTypeLevels["error"]=Globals::errorLogLevel;
  99. }
  100. LogLevel* ApacheReader::getTypeLevel(const TQString& type) {
  101. TQMap<TQString, LogLevel*>::iterator it;
  102. it=mapTypeLevels.find(type);
  103. if (it!=mapTypeLevels.end()) {
  104. return(*it);
  105. }
  106. else {
  107. kdDebug() << i18n("New Log Level detected: Please send this log file to the KSystemLog developer to add it.") << endl;
  108. return(Globals::noneLogLevel);
  109. }
  110. }
  111. #include "apacheReader.moc"