Last change
on this file since 123 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
|
Rev | Line | |
---|
[88] | 1 | /* |
---|
| 2 | * $Id: Message.cpp 120 2009-05-26 19:01:47Z rosiere $ |
---|
| 3 | * |
---|
| 4 | * [ Description ] |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
[115] | 8 | #include <sys/types.h> |
---|
[88] | 9 | #include "Common/include/Environment.h" |
---|
| 10 | #include "Common/include/ErrorMorpheo.h" |
---|
[100] | 11 | #include "Common/include/Filename.h" |
---|
[115] | 12 | #include "Common/include/Debug.h" |
---|
[88] | 13 | |
---|
| 14 | namespace morpheo { |
---|
| 15 | |
---|
[97] | 16 | static bool log_initialized; |
---|
[120] | 17 | bool log_with_pid; |
---|
[97] | 18 | FILE * log_stream; |
---|
| 19 | |
---|
[88] | 20 | #undef FUNCTION |
---|
[97] | 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 |
---|
[88] | 29 | #define FUNCTION "log_init" |
---|
[97] | 30 | void log_init (bool have_file, |
---|
[120] | 31 | bool with_pid , |
---|
[97] | 32 | std::string directory, |
---|
| 33 | std::string file) |
---|
| 34 | { |
---|
| 35 | if (not log_initialized) |
---|
| 36 | { |
---|
| 37 | log_initialized = true; |
---|
[120] | 38 | log_with_pid = with_pid; |
---|
| 39 | |
---|
[97] | 40 | if (have_file) |
---|
| 41 | { |
---|
| 42 | // if the file is not define, take pid. |
---|
[100] | 43 | std::string filename = morpheo::filename(directory, |
---|
| 44 | "Morpheo", |
---|
| 45 | "", |
---|
| 46 | "log", |
---|
| 47 | (file==""), |
---|
[120] | 48 | with_pid, |
---|
[100] | 49 | true); |
---|
[97] | 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 | |
---|
[88] | 70 | }; // end namespace morpheo |
---|
Note: See
TracBrowser
for help on using the repository browser.