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