source: trunk/IPs/systemC/processor/Morpheo/Common/src/Message.cpp @ 134

Last change on this file since 134 was 134, checked in by rosiere, 15 years ago

1) valgrind fix
2) debug file on/off

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1/*
2 * $Id: Message.cpp 134 2009-07-15 08:41:01Z rosiere $
3 *
4 * [ Description ]
5 *
6 */
7
8#include <sys/types.h>
9#include "Common/include/Environment.h"
10#include "Common/include/ErrorMorpheo.h"
11#include "Common/include/Filename.h"
12#include "Common/include/Debug.h"
13
14namespace morpheo {
15
16  static bool log_initialized;
17  FILE * log_stream;
18  bool   log_file_generate;
19 
20#undef  FUNCTION
21#define FUNCTION "log"
22  FILE * log (FILE * stream)
23  {
24    // if log stream is initialized, take this, else return the default stream.
25    return (log_initialized and (log_stream!=NULL))?log_stream:stream;
26  };
27 
28#undef  FUNCTION
29#define FUNCTION "log_init"
30  void log_init (bool        have_file,
31                 bool        with_date,
32                 bool        with_pid ,
33                 std::string directory,
34                 std::string file)
35  {
36    if (not log_initialized)
37      {
38        log_initialized   = true;
39        log_file_generate = have_file;
40
41        if (have_file)
42          {
43            // if the file is not define, take pid.
44            std::string filename = morpheo::filename(directory,
45                                                     "Morpheo",
46                                                     "",
47                                                     "log",
48                                                     with_date,
49                                                     with_pid,
50                                                     true);
51           
52            log_stream = fopen (filename.c_str(), "w");
53
54            if (log_stream==NULL)
55              {
56                fprintf(stderr,_("%s Error create log file \"%s\", take the standard output.\n"),MSG_ERROR,filename.c_str());
57                log_stream = stdout;
58              }
59            else
60              {
61                fprintf(stdout,_("%s Create log file \"%s\".\n"),MSG_INFORMATION,filename.c_str());
62              }
63          }
64        else
65          {
66            log_stream = NULL;
67          }
68      }
69  }
70 
71}; // end namespace morpheo
Note: See TracBrowser for help on using the repository browser.