+/****************************************************************************
+**
+** Copyright (C) 2011 Tito Eritja Real <jtitoo@gmail.com>
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see <http://www.gnu.org/licenses/>.
+**
+****************************************************************************/
+
#include "log.h"
#include <QDate>
#include <QMessageBox>
Log::Log(QString fileText,int verbosity)
:verbosity(verbosity)
{
- QString name = QString(APPLICATION_PATH);
- name.append(QDate::currentDate().toString(DATE_FORMAT));
- file = new QFile(name.append("_" + fileText));
+ if(verbosity>NOLOG_VERBOSITY){
+ QString name = QString(APPLICATION_PATH);
+ name.append(QDate::currentDate().toString(DATE_FORMAT));
+ file = new QFile(name.append("_" + fileText));
+
+ if (!file->open(QIODevice::WriteOnly | QIODevice::Text)){
+ qDebug() << "Error: Can not write Log file!";
+ return;
+ }
+ QTextStream out(file);
+ out << "start logging\n" << file << "out=" << &out << ", verbosity:" << verbosity << "(-1 no log, 0->debug, 1->info, 2->warn, 3->error)\n";
- if (!file->open(QIODevice::WriteOnly | QIODevice::Text)){
- qDebug() << "Error: Can not write Log file!";
- return;
}
- QTextStream out(file);
- out << "start logging\n" << file << "out=" << &out << ", verbosity:" << verbosity << "(0->debug, 1->info, 2->warn, 3->error)\n";
-
}
Log::Log(QWidget *win, QString fileText,int verbosity)
:verbosity(verbosity)
{
- QString name = QString(APPLICATION_PATH);
- name.append(QDate::currentDate().toString(DATE_FORMAT));
+ if(verbosity>NOLOG_VERBOSITY){
+ QString name = QString(APPLICATION_PATH);
+ name.append(QDate::currentDate().toString(DATE_FORMAT));
- file = new QFile(name.append("_" + fileText));
- if (!file->open(QIODevice::WriteOnly | QIODevice::Text)){
- QMessageBox::information(win, tr("GPSSniffer"),tr("Error: Can not write Log file!"));
+ file = new QFile(name.append("_" + fileText));
+ if (!file->open(QIODevice::WriteOnly | QIODevice::Text)){
+ QMessageBox::information(win, tr("GPSSniffer"),tr("Error: Can not write Log file!"));
- return;
+ return;
+ }
+ QTextStream out(file);
+ out << "start logging\n"<< file << "out=" << &out << ", verbosity:" << verbosity << "(0->debug, 1->info, 2->warn, 3->error)\n";
}
- QTextStream out(file);
- out << "start logging\n"<< file << "out=" << &out << ", verbosity:" << verbosity << "(0->debug, 1->info, 2->warn, 3->error)\n";
}
Log::~Log(){
}
void Log::debug(QString msg){
- QTextStream out(file);
- if(&out!=0){
- if(verbosity==0){
- out << QDateTime::currentDateTime().toString(CLEAN_DATE_FORMAT)<< " [DEBUG] " << msg << "\n";
+ if(verbosity>NOLOG_VERBOSITY){
+ QTextStream out(file);
+ if(&out!=0){
+ if(verbosity==0){
+ out << QDateTime::currentDateTime().toString(CLEAN_DATE_FORMAT)<< " [DEBUG] " << msg << "\n";
+ }
}
}
}
void Log::info(QString msg){
- QTextStream out(file);
- if(&out!=0){
- if(verbosity<=1){
- out << QDateTime::currentDateTime().toString(CLEAN_DATE_FORMAT)<< " [INFO] " << msg << "\n";
- }
+ if(verbosity>NOLOG_VERBOSITY){
+ QTextStream out(file);
+ if(&out!=0){
+ if(verbosity<=1){
+ out << QDateTime::currentDateTime().toString(CLEAN_DATE_FORMAT)<< " [INFO] " << msg << "\n";
+ }
+ }
}
}
void Log::warn(QString msg){
- QTextStream out(file);
- if(&out!=0){
- if(verbosity<=2){
- out << QDateTime::currentDateTime().toString(CLEAN_DATE_FORMAT)<< " [WARN] " << msg << "\n";
+ if(verbosity>NOLOG_VERBOSITY){
+ QTextStream out(file);
+ if(&out!=0){
+ if(verbosity<=2){
+ out << QDateTime::currentDateTime().toString(CLEAN_DATE_FORMAT)<< " [WARN] " << msg << "\n";
+ }
}
}
}
void Log::err(QString msg){
- QTextStream out(file);
- if(&out!=0){
- if(verbosity<=3){
- out << QDateTime::currentDateTime().toString(CLEAN_DATE_FORMAT)<< " [ERROR] " << msg << "\n";
+ if(verbosity>NOLOG_VERBOSITY){
+ QTextStream out(file);
+ if(&out!=0){
+ if(verbosity<=3){
+ out << QDateTime::currentDateTime().toString(CLEAN_DATE_FORMAT)<< " [ERROR] " << msg << "\n";
+ }
}
}
}