| Index: src/log-utils.h | 
| =================================================================== | 
| --- src/log-utils.h	(revision 7267) | 
| +++ src/log-utils.h	(working copy) | 
| @@ -33,6 +33,8 @@ | 
|  | 
| #ifdef ENABLE_LOGGING_AND_PROFILING | 
|  | 
| +class Logger; | 
| + | 
| // A memory buffer that increments its size as you write in it.  Size | 
| // is incremented with 'block_size' steps, never exceeding 'max_size'. | 
| // During growth, memory contents are never copied.  At the end of the | 
| @@ -89,28 +91,23 @@ | 
|  | 
|  | 
| // Functions and data for performing output of log messages. | 
| -class Log : public AllStatic { | 
| +class Log { | 
| public: | 
| -  // Opens stdout for logging. | 
| -  static void OpenStdout(); | 
|  | 
| -  // Opens file for logging. | 
| -  static void OpenFile(const char* name); | 
| +  // Performs process-wide initialization. | 
| +  void Initialize(); | 
|  | 
| -  // Opens memory buffer for logging. | 
| -  static void OpenMemoryBuffer(); | 
| - | 
| // Disables logging, but preserves acquired resources. | 
| -  static void stop() { is_stopped_ = true; } | 
| +  void stop() { is_stopped_ = true; } | 
|  | 
| -  // Frees all resources acquired in Open... functions. | 
| -  static void Close(); | 
| +  // Frees all resources acquired in Initialize and Open... functions. | 
| +  void Close(); | 
|  | 
| // See description in include/v8.h. | 
| -  static int GetLogLines(int from_pos, char* dest_buf, int max_size); | 
| +  int GetLogLines(int from_pos, char* dest_buf, int max_size); | 
|  | 
| // Returns whether logging is enabled. | 
| -  static bool IsEnabled() { | 
| +  bool IsEnabled() { | 
| return !is_stopped_ && (output_handle_ != NULL || output_buffer_ != NULL); | 
| } | 
|  | 
| @@ -118,16 +115,19 @@ | 
| static const int kMessageBufferSize = v8::V8::kMinimumSizeForLogLinesBuffer; | 
|  | 
| private: | 
| -  typedef int (*WritePtr)(const char* msg, int length); | 
| +  explicit Log(Logger* logger); | 
|  | 
| -  // Initialization function called from Open... functions. | 
| -  static void Init(); | 
| +  // Opens stdout for logging. | 
| +  void OpenStdout(); | 
|  | 
| -  // Write functions assume that mutex_ is acquired by the caller. | 
| -  static WritePtr Write; | 
| +  // Opens file for logging. | 
| +  void OpenFile(const char* name); | 
|  | 
| +  // Opens memory buffer for logging. | 
| +  void OpenMemoryBuffer(); | 
| + | 
| // Implementation of writing to a log file. | 
| -  static int WriteToFile(const char* msg, int length) { | 
| +  int WriteToFile(const char* msg, int length) { | 
| ASSERT(output_handle_ != NULL); | 
| size_t rv = fwrite(msg, 1, length, output_handle_); | 
| ASSERT(static_cast<size_t>(length) == rv); | 
| @@ -137,25 +137,27 @@ | 
| } | 
|  | 
| // Implementation of writing to a memory buffer. | 
| -  static int WriteToMemory(const char* msg, int length) { | 
| +  int WriteToMemory(const char* msg, int length) { | 
| ASSERT(output_buffer_ != NULL); | 
| return output_buffer_->Write(msg, length); | 
| } | 
|  | 
| +  bool write_to_file_; | 
| + | 
| // Whether logging is stopped (e.g. due to insufficient resources). | 
| -  static bool is_stopped_; | 
| +  bool is_stopped_; | 
|  | 
| // When logging is active, either output_handle_ or output_buffer_ is used | 
| // to store a pointer to log destination. If logging was opened via OpenStdout | 
| // or OpenFile, then output_handle_ is used. If logging was opened | 
| // via OpenMemoryBuffer, then output_buffer_ is used. | 
| // mutex_ should be acquired before using output_handle_ or output_buffer_. | 
| -  static FILE* output_handle_; | 
| +  FILE* output_handle_; | 
|  | 
| // Used when low-level profiling is active to save code object contents. | 
| -  static FILE* output_code_handle_; | 
| +  FILE* output_code_handle_; | 
|  | 
| -  static LogDynamicBuffer* output_buffer_; | 
| +  LogDynamicBuffer* output_buffer_; | 
|  | 
| // Size of dynamic buffer block (and dynamic buffer initial size). | 
| static const int kDynamicBufferBlockSize = 65536; | 
| @@ -164,16 +166,18 @@ | 
| static const int kMaxDynamicBufferSize = 50 * 1024 * 1024; | 
|  | 
| // Message to "seal" dynamic buffer with. | 
| -  static const char* kDynamicBufferSeal; | 
| +  static const char* const kDynamicBufferSeal; | 
|  | 
| // mutex_ is a Mutex used for enforcing exclusive | 
| // access to the formatting buffer and the log file or log memory buffer. | 
| -  static Mutex* mutex_; | 
| +  Mutex* mutex_; | 
|  | 
| // Buffer used for formatting log messages. This is a singleton buffer and | 
| // mutex_ should be acquired before using it. | 
| -  static char* message_buffer_; | 
| +  char* message_buffer_; | 
|  | 
| +  Logger* logger_; | 
| + | 
| friend class Logger; | 
| friend class LogMessageBuilder; | 
| }; | 
| @@ -185,7 +189,7 @@ | 
| public: | 
| // Create a message builder starting from position 0. This acquires the mutex | 
| // in the log as well. | 
| -  explicit LogMessageBuilder(); | 
| +  explicit LogMessageBuilder(Logger* logger); | 
| ~LogMessageBuilder() { } | 
|  | 
| // Append string data to the log message. | 
| @@ -211,16 +215,9 @@ | 
| // Write the log message to the log file currently opened. | 
| void WriteToLogFile(); | 
|  | 
| -  // A handler that is called when Log::Write fails. | 
| -  typedef void (*WriteFailureHandler)(); | 
| - | 
| -  static void set_write_failure_handler(WriteFailureHandler handler) { | 
| -    write_failure_handler = handler; | 
| -  } | 
| - | 
| private: | 
| -  static WriteFailureHandler write_failure_handler; | 
|  | 
| +  Log* log_; | 
| ScopedLock sl; | 
| int pos_; | 
| }; | 
|  |