win_logger.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. //
  6. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  7. // Use of this source code is governed by a BSD-style license that can be
  8. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  9. //
  10. // Logger implementation that can be shared by all environments
  11. // where enough posix functionality is available.
  12. #pragma once
  13. #include <stdint.h>
  14. #include <windows.h>
  15. #include <atomic>
  16. #include <memory>
  17. #include "rocksdb/env.h"
  18. namespace ROCKSDB_NAMESPACE {
  19. class SystemClock;
  20. namespace port {
  21. class WinLogger : public ROCKSDB_NAMESPACE::Logger {
  22. public:
  23. WinLogger(uint64_t (*gettid)(), SystemClock* clock, HANDLE file,
  24. const InfoLogLevel log_level = InfoLogLevel::ERROR_LEVEL);
  25. virtual ~WinLogger();
  26. WinLogger(const WinLogger&) = delete;
  27. WinLogger& operator=(const WinLogger&) = delete;
  28. void Flush() override;
  29. using ROCKSDB_NAMESPACE::Logger::Logv;
  30. void Logv(const char* format, va_list ap) override;
  31. size_t GetLogFileSize() const override;
  32. void DebugWriter(const char* str, int len);
  33. protected:
  34. Status CloseImpl() override;
  35. private:
  36. HANDLE file_;
  37. uint64_t (*gettid_)(); // Return the thread id for the current thread
  38. std::atomic_size_t log_size_;
  39. std::atomic_uint_fast64_t last_flush_micros_;
  40. SystemClock* clock_;
  41. bool flush_pending_;
  42. Status CloseInternal();
  43. const static uint64_t flush_every_seconds_ = 5;
  44. };
  45. } // namespace port
  46. } // namespace ROCKSDB_NAMESPACE