GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Logger.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2011-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <cstdio>
31
32#include <QMutex>
33#include <QMutexLocker>
34#include <QProcessEnvironment>
35
36#include "Logger.h"
37
38namespace octave
39{
40
41 Logger *Logger::s_instance = nullptr;
42 QMutex *Logger::s_mutex = nullptr;
43
45 : m_debugEnabled (false)
46 {
47 QProcessEnvironment pe (QProcessEnvironment::systemEnvironment ());
48
49 if (pe.value ("QTHANDLES_DEBUG", "0") != "0")
50 m_debugEnabled = true;
51 }
52
54 { }
55
56 Logger *
58 {
59 if (! s_instance)
60 {
61 s_instance = new Logger ();
62 s_mutex = new QMutex ();
63 }
64
65 return s_instance;
66 }
67
68#define STATIC_LOGGER(fun) \
69 void Logger::fun (const char *fmt, ...) \
70 { \
71 QMutexLocker lock (s_mutex); \
72 va_list vl; \
73 va_start (vl, fmt); \
74 instance ()->fun ## V (fmt, vl); \
75 va_end (vl); \
76 }
77
79
80 void
81 Logger::debugV (const char *fmt, va_list arg)
82 {
84 {
85 vfprintf (stderr, fmt, arg);
86 fprintf (stderr, "\n");
87 }
88 }
89
90}
#define STATIC_LOGGER(fun)
Definition: Logger.cc:68
static QMutex * s_mutex
Definition: Logger.h:45
static Logger * instance(void)
Definition: Logger.cc:57
void debugV(const char *fmt, va_list arg)
Definition: Logger.cc:81
Logger(void)
Definition: Logger.cc:44
static Logger * s_instance
Definition: Logger.h:44
bool m_debugEnabled
Definition: Logger.h:42
~Logger(void)
Definition: Logger.cc:53