| Index: src/log-utils.h
|
| ===================================================================
|
| --- src/log-utils.h (revision 3427)
|
| +++ src/log-utils.h (working copy)
|
| @@ -87,7 +87,49 @@
|
| bool is_sealed_;
|
| };
|
|
|
| +class LogData {
|
| + // Whether logging is stopped (e.g. due to insufficient resources).
|
| + 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_.
|
| + FILE* output_handle_;
|
| +
|
| + LogDynamicBuffer* output_buffer_;
|
| +
|
| + // mutex_ is a Mutex used for enforcing exclusive
|
| + // access to the formatting buffer and the log file or log memory buffer.
|
| + Mutex* mutex_;
|
| +
|
| + // Buffer used for formatting log messages. This is a singleton buffer and
|
| + // mutex_ should be acquired before using it.
|
| + char* message_buffer_;
|
| +
|
| + typedef int (*WritePtr)(const char* msg, int length);
|
| + // Write functions assume that mutex_ is acquired by the caller.
|
| + WritePtr Write;
|
| +
|
| + // A handler that is called when Log::Write fails.
|
| + typedef void (*WriteFailureHandler)();
|
| +
|
| + WriteFailureHandler write_failure_handler;
|
| +
|
| + void set_write_failure_handler(WriteFailureHandler handler) {
|
| + write_failure_handler = handler;
|
| + }
|
| +
|
| + friend class V8Context;
|
| + friend class Log;
|
| + friend class Logger;
|
| + friend class LogMessageBuilder;
|
| +
|
| + LogData();
|
| + DISALLOW_COPY_AND_ASSIGN(LogData);
|
| +};
|
| +
|
| // Functions and data for performing output of log messages.
|
| class Log : public AllStatic {
|
| public:
|
| @@ -101,7 +143,9 @@
|
| static void OpenMemoryBuffer();
|
|
|
| // Disables logging, but preserves acquired resources.
|
| - static void stop() { is_stopped_ = true; }
|
| + static void stop() {
|
| + v8_context()->log_data_.is_stopped_ = true;
|
| + }
|
|
|
| // Frees all resources acquired in Open... functions.
|
| static void Close();
|
| @@ -111,25 +155,23 @@
|
|
|
| // Returns whether logging is enabled.
|
| static bool IsEnabled() {
|
| - return !is_stopped_ && (output_handle_ != NULL || output_buffer_ != NULL);
|
| + LogData& log_data = v8_context()->log_data_;
|
| + return !log_data.is_stopped_ &&
|
| + (log_data.output_handle_ != NULL || log_data.output_buffer_ != NULL);
|
| }
|
|
|
| // Size of buffer used for formatting log messages.
|
| static const int kMessageBufferSize = 2048;
|
|
|
| private:
|
| - typedef int (*WritePtr)(const char* msg, int length);
|
| -
|
| // Initialization function called from Open... functions.
|
| static void Init();
|
|
|
| - // Write functions assume that mutex_ is acquired by the caller.
|
| - static WritePtr Write;
|
| -
|
| // Implementation of writing to a log file.
|
| static int WriteToFile(const char* msg, int length) {
|
| - ASSERT(output_handle_ != NULL);
|
| - size_t rv = fwrite(msg, 1, length, output_handle_);
|
| + LogData& log_data = v8_context()->log_data_;
|
| + ASSERT(log_data.output_handle_ != NULL);
|
| + size_t rv = fwrite(msg, 1, length, log_data.output_handle_);
|
| ASSERT(static_cast<size_t>(length) == rv);
|
| USE(rv);
|
| return length;
|
| @@ -137,39 +179,20 @@
|
|
|
| // Implementation of writing to a memory buffer.
|
| static int WriteToMemory(const char* msg, int length) {
|
| - ASSERT(output_buffer_ != NULL);
|
| - return output_buffer_->Write(msg, length);
|
| + LogData& log_data = v8_context()->log_data_;
|
| + ASSERT(log_data.output_buffer_ != NULL);
|
| + return log_data.output_buffer_->Write(msg, length);
|
| }
|
|
|
| - // Whether logging is stopped (e.g. due to insufficient resources).
|
| - static 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_;
|
| -
|
| - static LogDynamicBuffer* output_buffer_;
|
| -
|
| - // Size of dynamic buffer block (and dynamic buffer initial size).
|
| +// Size of dynamic buffer block (and dynamic buffer initial size).
|
| static const int kDynamicBufferBlockSize = 65536;
|
|
|
| // Maximum size of dynamic buffer.
|
| static const int kMaxDynamicBufferSize = 50 * 1024 * 1024;
|
|
|
| // Message to "seal" dynamic buffer with.
|
| - static const char* kDynamicBufferSeal;
|
| + static const char 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_;
|
| -
|
| - // Buffer used for formatting log messages. This is a singleton buffer and
|
| - // mutex_ should be acquired before using it.
|
| - static char* message_buffer_;
|
| -
|
| friend class LogMessageBuilder;
|
| friend class LogRecordCompressor;
|
| };
|
| @@ -271,16 +294,8 @@
|
| // Write a null-terminated string to to the log file currently opened.
|
| void WriteCStringToLogFile(const char* str);
|
|
|
| - // 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;
|
| -
|
| + LogData& log_data_;
|
| ScopedLock sl;
|
| int pos_;
|
| };
|
|
|