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

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

1) Context_state : Add statistics
2) Add configuration with multi front_end
3) Add optionnal pid at log filename

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