2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2015-07-01 23:13:49 +00:00
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
#include "rocksdb/env.h"
|
|
|
|
|
2015-11-16 22:41:11 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <Windows.h>
|
|
|
|
|
2015-07-01 23:13:49 +00:00
|
|
|
namespace rocksdb {
|
|
|
|
|
|
|
|
class Env;
|
|
|
|
|
|
|
|
const int kDebugLogChunkSize = 128 * 1024;
|
|
|
|
|
|
|
|
class WinLogger : public rocksdb::Logger {
|
2015-07-13 19:11:05 +00:00
|
|
|
public:
|
2015-08-27 01:51:18 +00:00
|
|
|
WinLogger(uint64_t (*gettid)(), Env* env, 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 close();
|
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
|
|
|
|
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);
|
|
|
|
|
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_;
|
2015-07-13 19:11:05 +00:00
|
|
|
Env* env_;
|
|
|
|
bool flush_pending_;
|
2015-07-01 23:13:49 +00:00
|
|
|
|
2015-07-07 23:58:20 +00:00
|
|
|
const static uint64_t flush_every_seconds_ = 5;
|
2015-07-01 23:13:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace rocksdb
|