| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef THIRD_PARTY_LEVELDATABASE_CHROMIUM_LOGGER_H_ | 5 #ifndef THIRD_PARTY_LEVELDATABASE_CHROMIUM_LOGGER_H_ |
| 6 #define THIRD_PARTY_LEVELDATABASE_CHROMIUM_LOGGER_H_ | 6 #define THIRD_PARTY_LEVELDATABASE_CHROMIUM_LOGGER_H_ |
| 7 | 7 |
| 8 #include <stdio.h> |
| 9 |
| 8 #include <algorithm> | 10 #include <algorithm> |
| 9 #include <stdio.h> | 11 |
| 10 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 12 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 13 #include "leveldb/env.h" | 15 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
| 14 | 16 |
| 15 namespace leveldb { | 17 namespace leveldb { |
| 16 | 18 |
| 17 class ChromiumLogger : public Logger { | 19 class ChromiumLogger : public Logger { |
| 18 public: | 20 public: |
| 19 ChromiumLogger(FILE* f) : file_(f) { } | 21 explicit ChromiumLogger(FILE* f) : file_(f) {} |
| 20 virtual ~ChromiumLogger() { | 22 virtual ~ChromiumLogger() { |
| 21 fclose(file_); | 23 fclose(file_); |
| 22 } | 24 } |
| 23 virtual void Logv(const char* format, va_list ap) { | 25 virtual void Logv(const char* format, va_list ap) { |
| 24 const long long unsigned int thread_id = | 26 const base::PlatformThreadId thread_id = |
| 25 ::base::PlatformThread::CurrentId(); | 27 ::base::PlatformThread::CurrentId(); |
| 26 | 28 |
| 27 // We try twice: the first time with a fixed-size stack allocated buffer, | 29 // We try twice: the first time with a fixed-size stack allocated buffer, |
| 28 // and the second time with a much larger dynamically allocated buffer. | 30 // and the second time with a much larger dynamically allocated buffer. |
| 29 char buffer[500]; | 31 char buffer[500]; |
| 30 for (int iter = 0; iter < 2; iter++) { | 32 for (int iter = 0; iter < 2; iter++) { |
| 31 char* base; | 33 char* base; |
| 32 int bufsize; | 34 int bufsize; |
| 33 if (iter == 0) { | 35 if (iter == 0) { |
| 34 bufsize = sizeof(buffer); | 36 bufsize = sizeof(buffer); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 80 |
| 79 assert(p <= limit); | 81 assert(p <= limit); |
| 80 fwrite(base, 1, p - base, file_); | 82 fwrite(base, 1, p - base, file_); |
| 81 fflush(file_); | 83 fflush(file_); |
| 82 if (base != buffer) { | 84 if (base != buffer) { |
| 83 delete[] base; | 85 delete[] base; |
| 84 } | 86 } |
| 85 break; | 87 break; |
| 86 } | 88 } |
| 87 } | 89 } |
| 90 |
| 88 private: | 91 private: |
| 89 FILE* file_; | 92 FILE* file_; |
| 90 }; | 93 }; |
| 91 | 94 |
| 92 } // namespace leveldb | 95 } // namespace leveldb |
| 93 | 96 |
| 94 #endif // THIRD_PARTY_LEVELDATABASE_CHROMIUM_LOGGER_H_ | 97 #endif // THIRD_PARTY_LEVELDATABASE_CHROMIUM_LOGGER_H_ |
| OLD | NEW |