GNU Octave  8.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-2023 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 
39 
40 Logger *Logger::s_instance = nullptr;
41 QMutex *Logger::s_mutex = nullptr;
42 
44  : m_debugEnabled (false)
45 {
46  QProcessEnvironment pe (QProcessEnvironment::systemEnvironment ());
47 
48  if (pe.value ("QTHANDLES_DEBUG", "0") != "0")
49  m_debugEnabled = true;
50 }
51 
53 { }
54 
55 Logger *
57 {
58  if (! s_instance)
59  {
60  s_instance = new Logger ();
61  s_mutex = new QMutex ();
62  }
63 
64  return s_instance;
65 }
66 
67 #define STATIC_LOGGER(fcn) \
68  void Logger::fcn (const char *fmt, ...) \
69  { \
70  QMutexLocker lock (s_mutex); \
71  va_list vl; \
72  va_start (vl, fmt); \
73  instance ()->fcn ## V (fmt, vl); \
74  va_end (vl); \
75  }
76 
78 
79 void
80 Logger::debugV (const char *fmt, va_list arg)
81 {
82  if (m_debugEnabled)
83  {
84  vfprintf (stderr, fmt, arg);
85  fprintf (stderr, "\n");
86  }
87 }
88 
OCTAVE_END_NAMESPACE(octave)
#define STATIC_LOGGER(fcn)
Definition: Logger.cc:67
Definition: Logger.h:36
~Logger(void)
Definition: Logger.cc:52
Logger(void)
Definition: Logger.cc:43
static Logger * instance(void)
Definition: Logger.cc:56
static QMutex * s_mutex
Definition: Logger.h:44
bool m_debugEnabled
Definition: Logger.h:41
void debugV(const char *fmt, va_list arg)
Definition: Logger.cc:80
static Logger * s_instance
Definition: Logger.h:43
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn