[Qgis-developer] prints to std::cout in qgis

Tim Sutton tim at linfiniti.com
Mon Apr 3 11:24:03 EDT 2006


Hi

Adding __FUNCTION__ to my reports would also be useful

Tim



On 4/3/06, Mateusz Łoskot <mateusz at loskot.net> wrote:
> nhugent at hispeed.ch wrote:
> > Hi qgissers,
> >
> > I will have time to do the implementation of the logger class
> > tomorrow. My suggestion is a header as below. QgsLogger would query
> > the environment variables QGIS_DEBUG and (if set) QGIS_DEBUG_FILE and
> > print out messages or not.
>
> Yes.
>
> > The question is how the output should be
> > controled by QGIS_DEBUG. One possibility would be to have
> > QGIS_DEBUG=1 for fatal, QGIS_DEBUG=2 for fatal and critical,
> > QGIS_DEBUG=3 for fatal, critical, warning, etc. If QGIS_DEBUG_FILE is
> > set, only messages from that file will be printed. Else, messages
> > from all files will be printed. What do you think?
>
> I think this is a good idea.
>
> Here is a bit modified version of QgsLogger with simeple use case.
> Simply, I'd suggest to use template member what will make it possible to
> pass e.g. objects of class types that have ostream operator defined.
>
> #include <QtGlobal>
> #include <QString>
>
> #include <sstream>
>
> class QgsLogger
> {
> public:
>
> static void debug(QString msg, const char* file = 0, const char*
> function = 0)
> {
>    qDebug("File: %s\nFunction: %s\nMessage: %s",
>          file, function, msg.toLocal8Bit().data());
> }
>
> template <typename T>
> static void debug(QString var, T val, const char* file = 0, const char*
> function = 0)
> {
>    std::ostringstream os;
>    os << var.toLocal8Bit().data() << " = " << val;
>
>    qDebug("File: %s\nFunction: %s\nMessage: %s",
>          file, function, os.str().c_str());
> }
>
>
> // REST OF FUCTIONS
>
> };
>
> Simple use case:
>
>
>
> #include "qgslogger.h"
>
> void foo(int x)
> {
>    QgsLogger::debug("x", x, __FILE__, __FUNCTION__);
> }
>
> int main()
> {
>    QgsLogger::debug("Error occured", __FILE__, __FUNCTION__);
>
>    foo(19);
>
>    return 0;
> }
>
> Cheers
> --
> Mateusz Łoskot
> http://mateusz.loskot.net
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.qgis.org
> http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
>


--
Tim Sutton

Visit http://qgis.org for a great Open Source GIS
Skype: timlinux
MSN: tim_bdworld at msn.com
Yahoo: tim_bdworld at yahoo.com
Jabber: timlinux
Irc: timlinux on #qgis at freenode.net


More information about the Qgis-developer mailing list