Beispiel #1
0
void Debug::print(DebugLevel_t level, const QString& msg, const char* file,
                  int line) {
  QMutexLocker locker(&mMutex);

  if ((mDebugLevelStderr < level) &&
      ((mDebugLevelLogFile < level) || (!mLogFile)))
    return;  // if there is nothing to print, we will return immediately from
             // this function

  const char* levelStr =
      "---------";  // the debug level string has always 9 characters
  switch (level) {
    case DebugLevel_t::DebugMsg:
      levelStr = "DEBUG-MSG";
      break;
    case DebugLevel_t::Info:
      levelStr = "  INFO   ";
      break;
    case DebugLevel_t::Warning:
      levelStr = " WARNING ";
      break;
    case DebugLevel_t::Exception:
      levelStr = "EXCEPTION";
      break;
    case DebugLevel_t::Critical:
      levelStr = "CRITICAL ";
      break;
    case DebugLevel_t::Fatal:
      levelStr = "  FATAL  ";
      break;
    default:
      break;
  }

  QString logMsg = QString("[%1] %2 (%3:%4)")
                       .arg(levelStr, msg.toLocal8Bit().constData(), file)
                       .arg(line);

  if (mDebugLevelStderr >= level) {
    // write to stderr
    *mStderrStream << logMsg << endl;
  }

  if ((mDebugLevelLogFile >= level) && (mLogFile)) {
    // write to the log file
    QTextStream logFileStream(mLogFile);
    logFileStream << logMsg << endl;
  }
}
Beispiel #2
0
void kweather::slotPrefsAccepted()
{
    // Preferences have been saved in the config file by the TDECModule,
    // so read them out.
    loadPrefs();

    dockWidget->setLocationCode(reportLocation);
    dockWidget->setViewMode(mViewMode);
    setLabelColor();
    emit updateLayout();

    if (logOn && !fileName.isEmpty())
    {
        TQFile logFile(fileName);
        // Open the file, create it if not already exists
        if (logFile.open(IO_ReadWrite))
        {
            if (logFile.size() == 0)
            {
                // Empty file, put the header
                TQTextStream logFileStream(&logFile);
                logFileStream << "Date,Wind Speed & Direction,Temperature,Pressure,Cover,Visibility,Current Weather" << endl;
            }
            logFile.close();
        }
        else
        {
            kdDebug(12004) << "There was an error opening the file...." << endl;
            KMessageBox::sorry( this,
                    i18n("For some reason a new log file could not be opened.\n"
                    "Please check to see if your disk is full or if you have "
                    "write access to the location you are trying to write to."),
                    i18n("KWeather Error"));
        }
    }

    timeout();
}
Beispiel #3
0
void kweather::writeLogEntry()
{
    // Write data line in the CSV format
    if (logOn && !fileName.isEmpty())
    {
        kdDebug(12004)<< "Try log file:" << fileName << endl;
        TQFile logFile(fileName);
        TQTextStream logFileStream(&logFile);
        if (logFile.open(IO_Append | IO_ReadWrite))
        {
            TQString temperature = mWeatherService->temperature(reportLocation );
            TQString wind        = mWeatherService->wind(reportLocation );
            TQString pressure    = mWeatherService->pressure(reportLocation );
            TQString date        = mWeatherService->date(reportLocation );
            TQStringList weather = mWeatherService->weather(reportLocation );
            TQStringList cover   = mWeatherService->cover(reportLocation );
            TQString visibility  = mWeatherService->visibility(reportLocation );
            logFileStream << date << ",";
            logFileStream << wind << ",";
            logFileStream << temperature << ",";
            logFileStream << pressure << ",";
            logFileStream << cover.join(";") << ",";
            logFileStream << visibility << ",";
            logFileStream << weather.join(";");
            logFileStream << endl;
        }
        else
        {
            KMessageBox::sorry( this,
                    i18n("For some reason the log file could not be written to.\n"
                    "Please check to see if your disk is full or if you "
                    "have write access to the location you are trying to "
                    "write to."),
                    i18n("KWeather Error"));
        }
        logFile.close();
    }
}