1 /***************************************************************************
2 * Copyright (C) 2006 by David Cuadrado *
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. *
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, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
26 #include <dcore/globaldeleter.h>
28 DCore::GlobalDeleter
<DashServer::Logger
> deleter
;
30 namespace DashServer
{
32 struct Logger::Private
37 Logger
*Logger::s_self
= 0;
39 Logger::Logger() : d(new Private
)
41 d
->file
.setFileName("server.log");
50 Logger
*Logger::self()
55 deleter
.setObject(s_self
);
61 void Logger::setLogFile(const QString
&logfile
)
63 d
->file
.setFileName(logfile
);
66 QString
Logger::logFile() const
68 return d
->file
.fileName();
72 void Logger::warn(const QString
&log
)
74 write(QString(QDateTime::currentDateTime().toString(Qt::ISODate
)+ " WARNING: "+log
+"\n").toLocal8Bit());
77 void Logger::error(const QString
&log
)
79 write(QString(QDateTime::currentDateTime().toString(Qt::ISODate
)+ " ERROR: "+log
+"\n").toLocal8Bit());
82 void Logger::info(const QString
&log
)
84 write(QString(QDateTime::currentDateTime().toString(Qt::ISODate
)+ " INFO: "+log
+"\n").toLocal8Bit());
87 void Logger::fatal(const QString
&log
)
89 write(QString(QDateTime::currentDateTime().toString(Qt::ISODate
)+ " FATAL: "+log
+"\n").toLocal8Bit());
92 void Logger::write(const QByteArray
&msg
)
94 if ( d
->file
.open(QIODevice::Append
| QIODevice::Text
))
96 d
->file
.write(msg
.data(), msg
.size());