win_logger.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 <atomic>
  14. #include "rocksdb/env.h"
  15. #include <stdint.h>
  16. #include <windows.h>
  17. namespace ROCKSDB_NAMESPACE {
  18. class Env;
  19. namespace port {
  20. class WinLogger : public ROCKSDB_NAMESPACE::Logger {
  21. public:
  22. WinLogger(uint64_t (*gettid)(), Env* env, HANDLE file,
  23. const InfoLogLevel log_level = InfoLogLevel::ERROR_LEVEL);
  24. virtual ~WinLogger();
  25. WinLogger(const WinLogger&) = delete;
  26. WinLogger& operator=(const WinLogger&) = delete;
  27. void Flush() override;
  28. using ROCKSDB_NAMESPACE::Logger::Logv;
  29. void Logv(const char* format, va_list ap) override;
  30. size_t GetLogFileSize() const override;
  31. void DebugWriter(const char* str, int len);
  32. protected:
  33. Status CloseImpl() override;
  34. private:
  35. HANDLE file_;
  36. uint64_t (*gettid_)(); // Return the thread id for the current thread
  37. std::atomic_size_t log_size_;
  38. std::atomic_uint_fast64_t last_flush_micros_;
  39. Env* env_;
  40. bool flush_pending_;
  41. Status CloseInternal();
  42. const static uint64_t flush_every_seconds_ = 5;
  43. };
  44. }
  45. } // namespace ROCKSDB_NAMESPACE