We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Synchronize debug and log output writing by buffering the intermediate 
result.
Hongli Lai (Phusion) (author)
Tue Jul 22 08:48:01 -0700 2008
commit  84eb0e2889f2c1f4a9c196661e02aa8facb451a9
tree    cd8c576c72f143d150d20576a7ea8b40a5b2a4e8
parent  5d00cf2ecc36b4232a94976dbdd4722fb8bfcc1f
...
24
25
26
 
27
28
29
...
39
40
41
42
 
 
 
 
43
44
 
45
46
47
48
49
50
 
 
 
 
 
 
 
 
 
51
52
53
 
54
55
56
 
 
 
57
58
59
60
 
 
 
 
 
61
62
63
...
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
94
95
96
...
24
25
26
27
28
29
30
...
40
41
42
 
43
44
45
46
47
 
48
49
 
 
 
 
 
50
51
52
53
54
55
56
57
58
59
60
 
61
62
63
 
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
...
94
95
96
 
 
 
 
 
 
 
 
 
 
 
 
97
98
99
100
0
@@ -24,6 +24,7 @@
0
 #include <sys/time.h>
0
 #include <unistd.h>
0
 #include <ostream>
0
+#include <sstream>
0
 #include <ctime>
0
 
0
 namespace Passenger {
0
@@ -39,25 +40,39 @@ void setLogLevel(unsigned int value);
0
 void setDebugFile(const char *logFile = NULL);
0
 
0
 /**
0
- * Write the given expression to the log stream.
0
+ * Write the given expression to the given stream.
0
+ *
0
+ * @param expr The expression to write.
0
+ * @param stream A pointer to an object that accepts the '<<' operator.
0
  */
0
-#define P_LOG(expr) \
0
+#define P_LOG_TO(expr, stream) \
0
   do { \
0
- if (Passenger::_logStream != 0) { \
0
- time_t the_time = time(NULL); \
0
- struct tm *the_tm = localtime(&the_time); \
0
- char datetime_buf[60]; \
0
- struct timeval tv; \
0
+ if (stream != 0) { \
0
+ time_t the_time; \
0
+ struct tm *the_tm; \
0
+ char datetime_buf[60]; \
0
+ struct timeval tv; \
0
+ std::stringstream sstream; \
0
+ \
0
+ the_time = time(NULL); \
0
+ the_tm = localtime(&the_time); \
0
       strftime(datetime_buf, sizeof(datetime_buf), "%F %H:%M:%S", the_tm); \
0
       gettimeofday(&tv, NULL); \
0
- *Passenger::_logStream << \
0
+ sstream << \
0
         "[ pid=" << getpid() << " file=" << __FILE__ << ":" << __LINE__ << \
0
         " time=" << datetime_buf << "." << (tv.tv_usec / 1000) << " ]:" << \
0
- "\n " << expr << std::endl; \
0
+ "\n " << expr << std::endl; \
0
+ *stream << sstream.str(); \
0
+ stream->flush(); \
0
     } \
0
   } while (false)
0
 
0
 /**
0
+ * Write the given expression to the log stream.
0
+ */
0
+#define P_LOG(expr) P_LOG_TO(expr, Passenger::_logStream)
0
+
0
+/**
0
  * Write the given expression, which represents a warning,
0
  * to the log stream.
0
  */
0
@@ -79,18 +94,7 @@ void setDebugFile(const char *logFile = NULL);
0
   #define P_TRACE(level, expr) \
0
     do { \
0
       if (Passenger::_logLevel >= level) { \
0
- if (Passenger::_debugStream != 0) { \
0
- time_t the_time = time(NULL); \
0
- struct tm *the_tm = localtime(&the_time); \
0
- char datetime_buf[60]; \
0
- struct timeval tv; \
0
- strftime(datetime_buf, sizeof(datetime_buf), "%F %H:%M:%S", the_tm); \
0
- gettimeofday(&tv, NULL); \
0
- *Passenger::_debugStream << \
0
- "[ pid=" << getpid() << " file=" << __FILE__ << ":" << __LINE__ << \
0
- " time=" << datetime_buf << "." << (tv.tv_usec / 1000) << " ]:" << \
0
- "\n " << expr << std::endl; \
0
- } \
0
+ P_LOG_TO(expr, Passenger::_debugStream); \
0
       } \
0
     } while (false)
0
   

Comments

    No one has commented yet.