2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2015-07-01 23:13:49 +00:00
|
|
|
//
|
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
//
|
|
|
|
// Logger implementation that can be shared by all environments
|
|
|
|
// where enough posix functionality is available.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-01-06 18:48:24 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <windows.h>
|
|
|
|
|
2015-07-01 23:13:49 +00:00
|
|
|
#include <atomic>
|
2021-01-06 18:48:24 +00:00
|
|
|
#include <memory>
|
2015-07-01 23:13:49 +00:00
|
|
|
|
|
|
|
#include "rocksdb/env.h"
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2021-01-26 06:07:26 +00:00
|
|
|
class SystemClock;
|
2015-07-01 23:13:49 +00:00
|
|
|
|
2016-05-19 23:40:54 +00:00
|
|
|
namespace port {
|
2020-02-20 20:07:53 +00:00
|
|
|
class WinLogger : public ROCKSDB_NAMESPACE::Logger {
|
2015-07-13 19:11:05 +00:00
|
|
|
public:
|
2021-03-15 11:32:24 +00:00
|
|
|
WinLogger(uint64_t (*gettid)(), SystemClock* clock, HANDLE file,
|
2015-07-07 23:58:20 +00:00
|
|
|
const InfoLogLevel log_level = InfoLogLevel::ERROR_LEVEL);
|
2015-07-01 23:13:49 +00:00
|
|
|
|
2015-07-07 23:58:20 +00:00
|
|
|
virtual ~WinLogger();
|
2015-07-01 23:13:49 +00:00
|
|
|
|
2015-07-07 23:58:20 +00:00
|
|
|
WinLogger(const WinLogger&) = delete;
|
|
|
|
|
|
|
|
WinLogger& operator=(const WinLogger&) = delete;
|
2015-07-01 23:13:49 +00:00
|
|
|
|
2015-07-07 23:58:20 +00:00
|
|
|
void Flush() override;
|
2015-07-01 23:13:49 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
using ROCKSDB_NAMESPACE::Logger::Logv;
|
2015-07-07 23:58:20 +00:00
|
|
|
void Logv(const char* format, va_list ap) override;
|
2015-07-01 23:13:49 +00:00
|
|
|
|
2015-07-07 23:58:20 +00:00
|
|
|
size_t GetLogFileSize() const override;
|
|
|
|
|
|
|
|
void DebugWriter(const char* str, int len);
|
|
|
|
|
2022-10-24 23:56:01 +00:00
|
|
|
protected:
|
|
|
|
Status CloseImpl() override;
|
2018-03-06 19:47:42 +00:00
|
|
|
|
2015-07-13 19:11:05 +00:00
|
|
|
private:
|
2015-08-27 01:51:18 +00:00
|
|
|
HANDLE file_;
|
2015-07-13 19:11:05 +00:00
|
|
|
uint64_t (*gettid_)(); // Return the thread id for the current thread
|
|
|
|
std::atomic_size_t log_size_;
|
2015-07-07 23:58:20 +00:00
|
|
|
std::atomic_uint_fast64_t last_flush_micros_;
|
2021-03-15 11:32:24 +00:00
|
|
|
SystemClock* clock_;
|
2015-07-13 19:11:05 +00:00
|
|
|
bool flush_pending_;
|
2015-07-01 23:13:49 +00:00
|
|
|
|
2018-03-06 19:47:42 +00:00
|
|
|
Status CloseInternal();
|
|
|
|
|
2015-07-07 23:58:20 +00:00
|
|
|
const static uint64_t flush_every_seconds_ = 5;
|
2015-07-01 23:13:49 +00:00
|
|
|
};
|
2022-10-24 23:56:01 +00:00
|
|
|
} // namespace port
|
2016-05-19 23:40:54 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|