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.

107 lines
3.6KB

  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 "cupsReader.h"
  24. #define DEBUG2_LOG_LEVEL_ICON "text-x-src"
  25. CupsReader::CupsReader(TQObject *parent, const char *name) :
  26. DefaultReader(parent, name)
  27. {
  28. initializeTypeLevels();
  29. }
  30. CupsReader::~CupsReader() {
  31. }
  32. void CupsReader::initColumns(LogViewColumns* columns) {
  33. columns->append(new LogViewColumn(i18n("Date"), true, false));
  34. columns->append(new LogViewColumn(i18n("Message"), true, false));
  35. }
  36. LogLine* CupsReader::parseMessage(TQString& logLine, LogFile* logFile) {
  37. /*
  38. * Log line examples :
  39. * I [15/Feb/2004:01:29:32 +0100] LoadPPDs: No new or changed PPDs...
  40. * E [15/Feb/2004:01:43:15 +0100] Scheduler shutting down due to SIGTERM.
  41. */
  42. TQChar level=logLine[0];
  43. TQString strDateTime=logLine.mid(2, 28);
  44. TQDateTime dateTime=ParsingHelper::parseDateTimeFromHTTP(strDateTime);
  45. TQDate date=dateTime.date();
  46. TQTime time=dateTime.time();
  47. TQString message=logLine.remove(0, 31);
  48. LogLevel* logLevel=getTypeLevel(level);
  49. TQStringList list;
  50. list.push_back(message);
  51. TQString filePath=logFile->url.path();
  52. LogLine* line=new LogLine(date, time, list, filePath, logLevel, Globals::cupsMode->id);
  53. return(line);
  54. }
  55. void CupsReader::initializeTypeLevels() {
  56. mapTypeLevels['d']=new LogLevel(20, i18n("debug 2"), DEBUG2_LOG_LEVEL_ICON, TQColor(169, 189, 165));
  57. mapTypeLevels['D']=Globals::debugLogLevel;
  58. mapTypeLevels['I']=Globals::informationLogLevel;
  59. mapTypeLevels['N']=Globals::noticeLogLevel;
  60. mapTypeLevels['W']=Globals::warningLogLevel;
  61. mapTypeLevels['E']=Globals::errorLogLevel;
  62. mapTypeLevels['C']=Globals::criticalLogLevel;
  63. mapTypeLevels['A']=Globals::alertLogLevel;
  64. mapTypeLevels['X']=Globals::emergencyLogLevel;
  65. mapTypeLevels[' ']=Globals::noneLogLevel;
  66. }
  67. LogLevel* CupsReader::getTypeLevel(const TQChar& type) {
  68. TQMap<TQChar, LogLevel*>::iterator it;
  69. it=mapTypeLevels.find(type);
  70. if (it!=mapTypeLevels.end()) {
  71. return(*it);
  72. }
  73. else {
  74. kdDebug() << i18n("New Log Level detected: Please send this log file to the KSystemLog developer to add it.") << endl;
  75. return(Globals::noneLogLevel);
  76. }
  77. }
  78. #include "cupsReader.moc"