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.

170 lines
5.1KB

  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 "sambaReader.h"
  24. SambaReader::SambaReader(TQObject *parent, const char *name) :
  25. DefaultReader(parent, name)
  26. {
  27. }
  28. SambaReader::~SambaReader() {
  29. }
  30. void SambaReader::initColumns(LogViewColumns* columns) {
  31. columns->append(new LogViewColumn(i18n("Date"), true, false));
  32. columns->append(new LogViewColumn(i18n("Source File"), true, true));
  33. columns->append(new LogViewColumn(i18n("Function"), true, true));
  34. columns->append(new LogViewColumn(i18n("Line"), true, true));
  35. columns->append(new LogViewColumn(i18n("Message"), true, false));
  36. }
  37. LogLine* SambaReader::parseMessage(TQString& logLine, LogFile* logFile) {
  38. /*
  39. * Log line examples :
  40. * [2005/06/27 21:06:01, 0] nmbd/nmbd.c:main(668)
  41. * Netbios nameserver version 3.0.14a started.
  42. * Copyright Andrew Tridgell and the Samba Team 1994-2004
  43. * [2005/06/27 21:11:46, 0] nmbd/nmbd_become_lmb.c:become_local_master_stage2(396)
  44. * *****
  45. * Samba name server STEAKHACHE is now a local master browser for workgroup MAISON on subnet 192.168.1.33
  46. *
  47. * *****
  48. * [2005/06/28 06:41:03, 0] nmbd/nmbd.c:terminate(56)
  49. * Got SIGTERM: going down...
  50. * [2005/06/28 18:08:11, 0] nmbd/nmbd.c:main(668)
  51. * Netbios nameserver version 3.0.14a started.
  52. * Copyright Andrew Tridgell and the Samba Team 1994-2004
  53. */
  54. //The Date
  55. int dateBegin=logLine.find("[");
  56. int dateEnd=logLine.find("]");
  57. TQString strDate=logLine.mid(dateBegin+1, dateEnd-dateBegin-1);
  58. TQString year=strDate.mid(0, 4);
  59. TQString month=strDate.mid(5, 2);
  60. TQString day=strDate.mid(8, 2);
  61. TQString hour=strDate.mid(11, 2);
  62. TQString min=strDate.mid(14, 2);
  63. TQString sec=strDate.mid(17, 2);
  64. TQDate date=TQDate(year.toInt(), month.toInt(), day.toInt());
  65. TQTime time=TQTime(hour.toInt(), min.toInt(), sec.toInt());
  66. logLine=logLine.remove(0, dateEnd+2);
  67. //The source file
  68. int doubleDot;
  69. doubleDot=logLine.find(":");
  70. TQString file=logLine.left(doubleDot);
  71. logLine=logLine.remove(0, doubleDot+1);
  72. //The function
  73. int bracket=logLine.find("(");
  74. TQString function=logLine.left(bracket);
  75. logLine=logLine.remove(0, bracket+1);
  76. //The line number
  77. bracket=logLine.find(")");
  78. TQString lineNumber=logLine.left(bracket);
  79. //Remove the first return character and the two useless space of the first message line
  80. logLine=logLine.remove(0, bracket+4);
  81. //Message
  82. //Remove the last \n
  83. logLine=logLine.left(logLine.length()-1);
  84. //Remove return characters and 2 first spaces at each lines
  85. TQString message=logLine.replace("\n ", " / ");
  86. //TQString message=logLine.replace("\n", " / ");
  87. TQStringList list;
  88. list.push_back(file);
  89. list.push_back(function);
  90. list.push_back(lineNumber);
  91. list.push_back(message);
  92. TQString filePath=logFile->url.path();
  93. LogLine* line=new LogLine(date, time, list, filePath, Globals::informationLogLevel, Globals::sambaMode->id);
  94. return(line);
  95. }
  96. TQStringList* SambaReader::getRawBuffer(TQFile* file) {
  97. kdDebug() << "Retrieving the raw buffer..." << endl;
  98. TQString line;
  99. TQString buffer;
  100. TQString tmpBuffer;
  101. TQStringList* rawBuffer=new TQStringList();
  102. int res;
  103. //Insert the content of the file in a string list
  104. while(!file->atEnd()) {
  105. //Read the first MaxCharactersRead characters
  106. res=file->readLine(buffer, tmpMaxCharacters);
  107. //Ignore the rest of the line
  108. while(res==tmpMaxCharacters)
  109. file->readLine(tmpBuffer, tmpMaxCharacters);
  110. if (buffer[0]=='[') {
  111. //If it is not the first time we add a line
  112. if (!line.isNull()) {
  113. //Push the new buffer to the list
  114. rawBuffer->push_back(line);
  115. }
  116. line=buffer;
  117. }
  118. else {
  119. //line+='\n';
  120. line+=buffer;
  121. }
  122. }
  123. kdDebug() << "Raw buffer retrieved." << endl;
  124. return(rawBuffer);
  125. }
  126. #include "sambaReader.moc"