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

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

1) Add test and configuration
2) Fix Bug
3) Add log file in load store unit
4) Fix Bug in environment

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