| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Size of buffer used for formatting log messages. | 63 // Size of buffer used for formatting log messages. |
| 64 static const int kMessageBufferSize = 2048; | 64 static const int kMessageBufferSize = 2048; |
| 65 | 65 |
| 66 // This mode is only used in tests, as temporary files are automatically | 66 // This mode is only used in tests, as temporary files are automatically |
| 67 // deleted on close and thus can't be accessed afterwards. | 67 // deleted on close and thus can't be accessed afterwards. |
| 68 static const char* const kLogToTemporaryFile; | 68 static const char* const kLogToTemporaryFile; |
| 69 static const char* const kLogToConsole; | 69 static const char* const kLogToConsole; |
| 70 | 70 |
| 71 // Utility class for formatting log messages. It fills the message into the |
| 72 // static buffer in Log. |
| 73 class MessageBuilder BASE_EMBEDDED { |
| 74 public: |
| 75 // Create a message builder starting from position 0. |
| 76 // This acquires the mutex in the log as well. |
| 77 explicit MessageBuilder(Log* log); |
| 78 ~MessageBuilder() { } |
| 79 |
| 80 // Append string data to the log message. |
| 81 void Append(const char* format, ...); |
| 82 |
| 83 // Append string data to the log message. |
| 84 void AppendVA(const char* format, va_list args); |
| 85 |
| 86 // Append a character to the log message. |
| 87 void Append(const char c); |
| 88 |
| 89 // Append double quoted string to the log message. |
| 90 void AppendDoubleQuotedString(const char* string); |
| 91 |
| 92 // Append a heap string. |
| 93 void Append(String* str); |
| 94 |
| 95 // Appends an address. |
| 96 void AppendAddress(Address addr); |
| 97 |
| 98 void AppendSymbolName(Symbol* symbol); |
| 99 |
| 100 void AppendDetailed(String* str, bool show_impl_info); |
| 101 |
| 102 // Append a portion of a string. |
| 103 void AppendStringPart(const char* str, int len); |
| 104 |
| 105 // Write the log message to the log file currently opened. |
| 106 void WriteToLogFile(); |
| 107 |
| 108 private: |
| 109 Log* log_; |
| 110 ScopedLock sl; |
| 111 int pos_; |
| 112 }; |
| 113 |
| 71 private: | 114 private: |
| 72 explicit Log(Logger* logger); | 115 explicit Log(Logger* logger); |
| 73 | 116 |
| 74 // Opens stdout for logging. | 117 // Opens stdout for logging. |
| 75 void OpenStdout(); | 118 void OpenStdout(); |
| 76 | 119 |
| 77 // Opens file for logging. | 120 // Opens file for logging. |
| 78 void OpenFile(const char* name); | 121 void OpenFile(const char* name); |
| 79 | 122 |
| 80 // Opens a temporary file for logging. | 123 // Opens a temporary file for logging. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 101 // access to the formatting buffer and the log file or log memory buffer. | 144 // access to the formatting buffer and the log file or log memory buffer. |
| 102 Mutex* mutex_; | 145 Mutex* mutex_; |
| 103 | 146 |
| 104 // Buffer used for formatting log messages. This is a singleton buffer and | 147 // Buffer used for formatting log messages. This is a singleton buffer and |
| 105 // mutex_ should be acquired before using it. | 148 // mutex_ should be acquired before using it. |
| 106 char* message_buffer_; | 149 char* message_buffer_; |
| 107 | 150 |
| 108 Logger* logger_; | 151 Logger* logger_; |
| 109 | 152 |
| 110 friend class Logger; | 153 friend class Logger; |
| 111 friend class LogMessageBuilder; | |
| 112 }; | 154 }; |
| 113 | 155 |
| 114 | 156 |
| 115 // Utility class for formatting log messages. It fills the message into the | |
| 116 // static buffer in Log. | |
| 117 class LogMessageBuilder BASE_EMBEDDED { | |
| 118 public: | |
| 119 // Create a message builder starting from position 0. This acquires the mutex | |
| 120 // in the log as well. | |
| 121 explicit LogMessageBuilder(Logger* logger); | |
| 122 ~LogMessageBuilder() { } | |
| 123 | |
| 124 // Append string data to the log message. | |
| 125 void Append(const char* format, ...); | |
| 126 | |
| 127 // Append string data to the log message. | |
| 128 void AppendVA(const char* format, va_list args); | |
| 129 | |
| 130 // Append a character to the log message. | |
| 131 void Append(const char c); | |
| 132 | |
| 133 // Append double quoted string to the log message. | |
| 134 void AppendDoubleQuotedString(const char* string); | |
| 135 | |
| 136 // Append a heap string. | |
| 137 void Append(String* str); | |
| 138 | |
| 139 // Appends an address. | |
| 140 void AppendAddress(Address addr); | |
| 141 | |
| 142 void AppendDetailed(String* str, bool show_impl_info); | |
| 143 | |
| 144 // Append a portion of a string. | |
| 145 void AppendStringPart(const char* str, int len); | |
| 146 | |
| 147 // Write the log message to the log file currently opened. | |
| 148 void WriteToLogFile(); | |
| 149 | |
| 150 private: | |
| 151 Log* log_; | |
| 152 ScopedLock sl; | |
| 153 int pos_; | |
| 154 }; | |
| 155 | |
| 156 } } // namespace v8::internal | 157 } } // namespace v8::internal |
| 157 | 158 |
| 158 #endif // V8_LOG_UTILS_H_ | 159 #endif // V8_LOG_UTILS_H_ |
| OLD | NEW |