Bonjour a tous,

alors voici, j'ai ecrie un fichier log.h qui contient des MACRO permettant de créer une lib de Trace, et la voila :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef LOG_H_INCLUDED
#define LOG_H_INCLUDED
#define LOG_FILE    "/tmp/apc.log"
#ifdef DEBUG_CONSOLE
#define LOG_START()
#define LOG(mesg, args...)   fprintf(stderr, "%s: (function %s line %d):",__FILE__,__FUNCTION__,__LINE__); \
                             fprintf(stderr, mesg "\n", ##args)
#define LOG_END()
#endif  // DEBUG_CONSOLE

#ifdef DEBUG_FILE
#define LOG_START()         FILE *log_file_decriptor; \
                            if((log_file_decriptor=fopen(LOG_FILE, "w"))==NULL) \
                            LOG("LOG can not start.")
#define LOG(mesg, args...)  fprintf(log_file_decriptor, "%s: (function %s line %d):",__FILE__,__FUNCTION__,__LINE__); \
                            fprintf(log_file_decriptor, mesg "\n", ##args)
#define LOG_END()           if(fclose(log_file_decriptor)!=0) \
                            LOG("LOG ERROR")
#endif  // DEBUF_FILE

 

#if !defined(DEBUG_FILE) || !defined(DEBUG_CONSOLE)
#define LOG_START()
#define LOG(mesg, args...)
#define LOG_END()
#endif
 
#endif // LOG_H_INCLUDED
pour le LOg sur la console sa marche avec DEBUG_CONSOLE
mais pour les fichier ça ne marche pas et je sais pas pourquoi ?

j'utilise le fichier comme suit :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
#include <log.h>
 
void function(type args, ...)
{
     LOG_START();
     ...
     LOG(Message);
     ...
     LOG_END();
}