SysIo  1.9.0
Embedded Library and tools
log.h
1 
8 #ifndef _SYSIO_LOG_H_
9 #define _SYSIO_LOG_H_
10 #include <sysio/defs.h>
11 #include <syslog.h>
12 #include <stdarg.h>
13 
14 #ifdef __cplusplus
15  extern "C" {
16 #endif
17 /* ========================================================================== */
18 
47 /* public variables ========================================================= */
48 
52 extern const char* __progname;
53 
54 /* internal public functions ================================================ */
59 void vLogInit (int mask);
60 
66 void vLogDaemonize (bool daemon);
67 
77 void vLogSetMask (int mask);
78 
83 int iLogMask (void);
84 
92 void vLog (int priority, const char *format, ...);
93 
100 const char * sLogPriorityStr (int priority);
101 
108 bool bLogIsDaemonized (void);
109 
110 #if defined(__DOXYGEN__)
111 
123 void assert(scalar expression);
124 
138 void assert_perror(int errnum);
139 
143 #define LOG_MASK(p)
144 
148 #define LOG_UPTO(p)
149 
154 #else
155 /* ========================================================================== */
156 #ifdef LOG_ASSERT
157 #ifdef _ASSERT_H
158 
159 # undef _ASSERT_H
160 # undef assert
161 # undef __ASSERT_VOID_CAST
162 # undef __ASSERT_FUNCTION
163 
164 # ifdef __USE_GNU
165 # undef assert_perror
166 # endif
167 
168 #endif /* assert.h */
169 
170 #include <features.h>
171 
172 /* This prints an "Assertion failed" message and aborts. */
173 extern void __vLogAssertFail (__const char *__assertion, __const char *__file,
174  unsigned int __line, __const char *__function)
175  __THROW __attribute__ ((__noreturn__));
176 
177 /* Likewise, but prints the error text for ERRNUM. */
178 extern void __vLogAssertPerrorFail (int __errnum, __const char *__file,
179  unsigned int __line,
180  __const char *__function)
181  __THROW __attribute__ ((__noreturn__));
182 
183 
184 #if defined __cplusplus && __GNUC_PREREQ (2,95)
185 # define __ASSERT_VOID_CAST static_cast<void>
186 #else
187 # define __ASSERT_VOID_CAST (void)
188 #endif
189 
190 /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
191  which contains the name of the function currently being defined.
192  This is broken in G++ before version 2.6.
193  C9x has a similar variable called __func__, but prefer the GCC one since
194  it demangles C++ function names. */
195 # if defined __cplusplus ? __GNUC_PREREQ (2, 6) : __GNUC_PREREQ (2, 4)
196 # define __ASSERT_FUNCTION __PRETTY_FUNCTION__
197 # else
198 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
199 # define __ASSERT_FUNCTION __func__
200 # else
201 # define __ASSERT_FUNCTION ((__const char *) 0)
202 # endif
203 # endif
204 
205 # define assert(expr) \
206  ((expr) \
207  ? __ASSERT_VOID_CAST (0) \
208  : __vLogAssertFail (__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION))
209 
210 # ifdef __USE_GNU
211 # define assert_perror(errnum) \
212  (!(errnum) \
213  ? __ASSERT_VOID_CAST (0) \
214  : __vLogAssertPerrorFail ((errnum), __FILE__, __LINE__, __ASSERT_FUNCTION))
215 # endif
216 
217 #else /* LOG_ASSERT defined */
218 #include <assert.h>
219 #endif /* LOG_ASSERT not defined */
220 // -----------------------------------------------------------------------------
221 #endif /* !defined(__DOXYGEN__) */
222 
223 /* ========================================================================== */
224 #ifdef __cplusplus
225  }
226 #endif
227 #endif /* _SYSIO_LOG_H_ defined */
int iLogMask(void)
Lecture du masque des priorités en cours.
void vLog(int priority, const char *format,...)
Affichage ou écriture d&#39;un message de log.
bool bLogIsDaemonized(void)
Indique si les messages sont redirigés vers les journaux systèmes.
void assert_perror(int errnum)
Vérifier un code d&#39;erreur et arrêter le programme.
const char * __progname
Nom du programme en cours.
void vLogSetMask(int mask)
Fixe le masque des priorités Les huit priorités sont LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO et LOG_DEBUG. Le bit correspondant à la priorité p est LOG_MASK(p). Certains systèmes fournissent aussi une macro LOG_UPTO(p) pour le masque de toutes les priorités jusqu&#39;à p incluses.
void vLogInit(int mask)
Intialise le module.
void vLogDaemonize(bool daemon)
Passe ou sort du mode daemon.
const char * sLogPriorityStr(int priority)
Chaîne de caractère associée à une priorité
void assert(scalar expression)
Terminer le programme en cas d&#39;échec d&#39;un test.