Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYMessageManager.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
23 #include "TYMessageManager.h"
24 
25 #if TY_USE_IHM
26 
27  #include <stdarg.h>
28 
29  #include "TYApplication.h"
31 
32  #define TR(id) OLocalizator::getString("TYMessageManager", (id))
33 
34  #ifdef _DEBUG
35 static bool bDebug = true;
36  #else
37 static bool bDebug = false;
38  #endif
39 
41 
43 
44 void TYMessageManager::format(int level, const char* message, ...)
45 {
46  if ((!bDebug) && (level == MSG_DEBUG))
47  {
48  return;
49  } // on n'affiche les msg debug qu'en mode debug...
50 
51  va_list args = nullptr;
52  char strLevel[1024];
53  char tmp[1024];
54  char msg[2048];
55 
56  switch (level)
57  {
58  case MSG_DEBUG:
59  sprintf_s(strLevel, "%s", TR("id_level_debug").toLatin1().data());
60  break;
61  case MSG_BENCH:
62  sprintf_s(strLevel, "%s", TR("id_level_bench").toLatin1().data());
63  break;
64  case MSG_INFO:
65  sprintf_s(strLevel, "%s", TR("id_level_info").toLatin1().data());
66  break;
67  case MSG_WARNING:
68  sprintf_s(strLevel, "%s", TR("id_level_warning").toLatin1().data());
69  break;
70  case MSG_ERROR:
71  sprintf_s(strLevel, "%s", TR("id_level_error").toLatin1().data());
72  break;
73  case MSG_FATAL:
74  sprintf_s(strLevel, "%s", TR("id_level_fatal").toLatin1().data());
75  break;
76  default:
77  strcpy_s(strLevel, "");
78  break;
79  }
80 
81  va_start(args, message);
82 
83  // Arguments
84  vsprintf_s(tmp, message, args);
85  // On construit le msg de la facon suivante :
86  // JJ/MM/AAAA - HH:MM:SS <niveau><message><retour a la ligne>
87  sprintf_s(msg, "%s %s%s", getStrDate(), strLevel, tmp);
88 
89  va_end(args);
90 
91  // Affichage/ecriture du message
92  output(msg, level);
93 }
94 
95 void TYMessageManager::output(const char* message, int level)
96 {
97  if (level > MSG_DEBUG) // on n'affiche les msg dans l'ihm que s'ils ne sont pas debug de toute facon...
98  {
99  writeOutputMsg(message);
100  qApp->processEvents();
101  }
102  else
103  {
104  // pour les msg de debug, on utilise la console...
105  OMessageManager::output(message, level);
106  }
107 }
108 
109 #else // TY_USE_IHM
110 
112 
114 
115 void TYMessageManager::format(int level, const char* message, ...)
116 {
117  OMessageManager::format(level, message);
118 }
119 
120 void TYMessageManager::output(const char* message, int level)
121 {
122  OMessageManager::output(message, level);
123 }
124 
125 #endif // TY_USE_IHM
#define TR(id)
void writeOutputMsg(QString msg)
Affiche un message dans la fenetre de sortie.
pour l'application Tympan (fichier header)
utilitaire pour la gestion des messages dans Tympan (fichier header)
virtual void output(const char *message, int level)
Definition: logging.cpp:356
static char * getStrDate()
Definition: logging.cpp:443
virtual void format(int level, const char *message,...)
Definition: logging.cpp:305
virtual void format(int level, const char *message,...)
virtual void output(const char *message, int level)
#define MSG_DEBUG
Definition: logging.h:25
#define MSG_INFO
Definition: logging.h:27
#define MSG_BENCH
Definition: logging.h:26
#define MSG_FATAL
Definition: logging.h:30
#define MSG_WARNING
Definition: logging.h:28
#define MSG_ERROR
Definition: logging.h:29