Added a way to add timestamps to the log file name
authorchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 15 Oct 2008 08:50:22 +0000 (08:50 +0000)
committerchristian.plesner.hansen@gmail.com <christian.plesner.hansen@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 15 Oct 2008 08:50:22 +0000 (08:50 +0000)
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@504 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/log.cc

index 72eb455..4505449 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "log.h"
 #include "platform.h"
+#include "string-stream.h"
 
 namespace v8 { namespace internal {
 
@@ -686,6 +687,37 @@ bool Logger::Setup() {
   if (open_log_file) {
     if (strcmp(FLAG_logfile, "-") == 0) {
       logfile_ = stdout;
+    } else if (strchr(FLAG_logfile, '%') != NULL) {
+      // If there's a '%' in the log file name we have to expand
+      // placeholders.
+      HeapStringAllocator allocator;
+      StringStream stream(&allocator);
+      for (const char* p = FLAG_logfile; *p; p++) {
+        if (*p == '%') {
+          p++;
+          switch (*p) {
+            case '\0':
+              // If there's a % at the end of the string we back up
+              // one character so we can escape the loop properly.
+              p--;
+              break;
+            case 't': {
+              // %t expands to the current time in milliseconds.
+              uint32_t time = static_cast<uint32_t>(OS::TimeCurrentMillis());
+              stream.Add("%u", time);
+              break;
+            }
+            default:
+              // All other %'s expand to themselves.
+              stream.Put(*p);
+              break;
+          }
+        } else {
+          stream.Put(*p);
+        }
+      }
+      SmartPointer<char> expanded = stream.ToCString();
+      logfile_ = OS::FOpen(*expanded, "w");
     } else {
       logfile_ = OS::FOpen(FLAG_logfile, "w");
     }