Refactored filename_t and file_event_handlers
This commit is contained in:
parent
65f8b0a16e
commit
5401731160
@ -11,7 +11,6 @@
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <chrono>
|
||||
#include <string_view>
|
||||
|
||||
@ -48,15 +47,6 @@ namespace sinks {
|
||||
class sink;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// In windows, add L prefix for filename literals (e.g. L"filename.txt")
|
||||
#define SPDLOG_FILENAME_T_INNER(s) L##s
|
||||
#define SPDLOG_FILENAME_T(s) SPDLOG_FILENAME_T_INNER(s)
|
||||
#else
|
||||
#define SPDLOG_FILENAME_T(s) s
|
||||
#endif
|
||||
|
||||
using filename_t = std::filesystem::path;
|
||||
using log_clock = std::chrono::system_clock;
|
||||
using sink_ptr = std::shared_ptr<sinks::sink>;
|
||||
using sinks_init_list = std::initializer_list<sink_ptr>;
|
||||
@ -146,16 +136,4 @@ private:
|
||||
[[noreturn]] SPDLOG_API void throw_spdlog_ex(const std::string &msg, int last_errno);
|
||||
[[noreturn]] SPDLOG_API void throw_spdlog_ex(std::string msg);
|
||||
|
||||
struct file_event_handlers {
|
||||
file_event_handlers()
|
||||
: before_open(nullptr),
|
||||
after_open(nullptr),
|
||||
before_close(nullptr),
|
||||
after_close(nullptr) {}
|
||||
|
||||
std::function<void(const filename_t &filename)> before_open;
|
||||
std::function<void(const filename_t &filename, std::FILE *file_stream)> after_open;
|
||||
std::function<void(const filename_t &filename, std::FILE *file_stream)> before_close;
|
||||
std::function<void(const filename_t &filename)> after_close;
|
||||
};
|
||||
} // namespace spdlog
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <tuple>
|
||||
|
||||
#include "../common.h"
|
||||
#include "../file_event_handlers.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
@ -30,7 +31,7 @@ public:
|
||||
void close();
|
||||
void write(const memory_buf_t &buf) const;
|
||||
size_t size() const;
|
||||
const filename_t &filename() const;
|
||||
const filename_t &filename() const;
|
||||
|
||||
private:
|
||||
const int open_tries_ = 5;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <ctime> // std::time_t
|
||||
#include <tuple>
|
||||
#include "../common.h"
|
||||
#include "../filename_t.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
@ -1,8 +1,19 @@
|
||||
//
|
||||
// Created by gabi on 12/5/24.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#ifndef FILE_EVENT_HANDLERS_H
|
||||
#define FILE_EVENT_HANDLERS_H
|
||||
#include <functional>
|
||||
#include "./filename_t.h"
|
||||
|
||||
#endif //FILE_EVENT_HANDLERS_H
|
||||
namespace spdlog {
|
||||
struct file_event_handlers {
|
||||
file_event_handlers()
|
||||
: before_open(nullptr),
|
||||
after_open(nullptr),
|
||||
before_close(nullptr),
|
||||
after_close(nullptr) {}
|
||||
|
||||
std::function<void(const filename_t &filename)> before_open;
|
||||
std::function<void(const filename_t &filename, std::FILE *file_stream)> after_open;
|
||||
std::function<void(const filename_t &filename, std::FILE *file_stream)> before_close;
|
||||
std::function<void(const filename_t &filename)> after_close;
|
||||
};
|
||||
} // namespace spdlog
|
||||
|
18
include/spdlog/filename_t.h
Normal file
18
include/spdlog/filename_t.h
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#ifdef _WIN32
|
||||
// In windows, add L prefix for filename literals (e.g. L"filename.txt")
|
||||
#define SPDLOG_FILENAME_T_INNER(s) L##s
|
||||
#define SPDLOG_FILENAME_T(s) SPDLOG_FILENAME_T_INNER(s)
|
||||
#else
|
||||
#define SPDLOG_FILENAME_T(s) s
|
||||
#endif
|
||||
|
||||
namespace spdlog {
|
||||
using filename_t = std::filesystem::path;
|
||||
} // namespace spdlog
|
Loading…
Reference in New Issue
Block a user