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