summarylogtreecommitdiffstats
path: root/ps-log_messages_all.patch
blob: 8e51dd16b8283a04e01cc211023a3e172fbdc7bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
--- a/src/core/manager.cc
+++ b/src/core/manager.cc
@@ -38,6 +38,7 @@
 
 #include <cstdio>
 #include <cstring>
+#include <ctime>
 #include <fstream>
 #include <sstream>
 #include <unistd.h>
@@ -74,6 +75,8 @@
 
 namespace core {
 
+extern int log_messages_fd;
+
 const int Manager::create_start;
 const int Manager::create_tied;
 const int Manager::create_quiet;
@@ -83,6 +86,21 @@ void
 Manager::push_log(const char* msg) {
   m_log_important->lock_and_push_log(msg, strlen(msg), 0);
   m_log_complete->lock_and_push_log(msg, strlen(msg), 0);
+
+  if (log_messages_fd >= 0) {
+    char buf[30];
+    time_t t = std::time(0);
+    std::tm* now = std::localtime(&t);
+
+    snprintf(buf, sizeof(buf), "%04u-%02u-%02u %2d:%02d:%02d ",
+        1900 + now->tm_year, now->tm_mon + 1, now->tm_mday,
+        now->tm_hour, now->tm_min, now->tm_sec);
+
+    std::string line(buf);
+    line += msg;
+    line += '\n';
+    ::write(log_messages_fd, line.c_str(), line.length());
+  }
 }
 
 Manager::Manager() :