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

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

1) Write queue with mealy
2) Network : fix bug
3) leak memory

  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1/*
2 * $Id: Message.cpp 115 2009-04-20 21:29:17Z 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                 std::string directory,
31                 std::string file)
32  {
33    if (not log_initialized)
34      {
35        log_initialized = true;
36       
37        if (have_file)
38          {
39            // if the file is not define, take pid.
40            std::string filename = morpheo::filename(directory,
41                                                     "Morpheo",
42                                                     "",
43                                                     "log",
44                                                     (file==""),
45                                                     (file==""),
46                                                     true);
47           
48            log_stream = fopen (filename.c_str(), "w");
49           
50            if (log_stream==NULL)
51              {
52                fprintf(stderr,_("%s Error create log file \"%s\", take the standard output.\n"),MSG_ERROR,filename.c_str());
53                log_stream = stdout;
54              }
55            else
56              {
57                fprintf(stdout,_("%s Create log file \"%s\".\n"),MSG_INFORMATION,filename.c_str());
58              }
59          }
60        else
61          {
62            log_stream = NULL;
63          }
64      }
65  }
66 
67}; // end namespace morpheo
Note: See TracBrowser for help on using the repository browser.