1 /****************************************************************************
3 ** Copyright (C) 2011 Tito Eritja Real <jtitoo@gmail.com>
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 3 of the License, or
8 ** (at your option) any later version.
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.
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ****************************************************************************/
22 #include <QMessageBox>
26 Log::Log(QString fileText,int verbosity)
29 if(verbosity>NOLOG_VERBOSITY){
30 QString name = QString(APPLICATION_PATH);
31 name.append(QDate::currentDate().toString(DATE_FORMAT));
32 file = new QFile(name.append("_" + fileText));
34 if (!file->open(QIODevice::WriteOnly | QIODevice::Text)){
35 qDebug() << "Error: Can not write Log file!";
38 QTextStream out(file);
39 out << "start logging\n" << file << "out=" << &out << ", verbosity:" << verbosity << "(-1 no log, 0->debug, 1->info, 2->warn, 3->error)\n";
44 Log::Log(QWidget *win, QString fileText,int verbosity)
47 if(verbosity>NOLOG_VERBOSITY){
48 QString name = QString(APPLICATION_PATH);
49 name.append(QDate::currentDate().toString(DATE_FORMAT));
51 file = new QFile(name.append("_" + fileText));
52 if (!file->open(QIODevice::WriteOnly | QIODevice::Text)){
53 QMessageBox::information(win, tr("GPSSniffer"),tr("Error: Can not write Log file!"));
57 QTextStream out(file);
58 out << "start logging\n"<< file << "out=" << &out << ", verbosity:" << verbosity << "(0->debug, 1->info, 2->warn, 3->error)\n";
69 void Log::setVerbosity(int num){
73 int Log::getVerbosity(){
77 void Log::debug(QString msg){
78 if(verbosity>NOLOG_VERBOSITY){
79 QTextStream out(file);
82 out << QDateTime::currentDateTime().toString(CLEAN_DATE_FORMAT)<< " [DEBUG] " << msg << "\n";
88 void Log::info(QString msg){
89 if(verbosity>NOLOG_VERBOSITY){
90 QTextStream out(file);
93 out << QDateTime::currentDateTime().toString(CLEAN_DATE_FORMAT)<< " [INFO] " << msg << "\n";
99 void Log::warn(QString msg){
100 if(verbosity>NOLOG_VERBOSITY){
101 QTextStream out(file);
104 out << QDateTime::currentDateTime().toString(CLEAN_DATE_FORMAT)<< " [WARN] " << msg << "\n";
110 void Log::err(QString msg){
111 if(verbosity>NOLOG_VERBOSITY){
112 QTextStream out(file);
115 out << QDateTime::currentDateTime().toString(CLEAN_DATE_FORMAT)<< " [ERROR] " << msg << "\n";