Skip to content

Commit

Permalink
Merge pull request #13 from F1F88/1.5-dev
Browse files Browse the repository at this point in the history
Bump version to 1.5.0
  • Loading branch information
F1F88 authored Dec 14, 2024
2 parents 359f2c0 + 47d0e9c commit 4287618
Show file tree
Hide file tree
Showing 113 changed files with 12,494 additions and 9,206 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ jobs:
if: runner.os == 'Windows'
uses: microsoft/setup-msbuild@v2

- name: Getting AMBuild
uses: actions/checkout@v4
with:
repository: alliedmodders/ambuild
path: ambuild

- name: Setup Python
uses: actions/setup-python@v5
with:
Expand Down
8 changes: 7 additions & 1 deletion AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class ExtensionConfig(object):
'-fvisibility=hidden',
]
cxx.cxxflags += [
'-std=c++17',
'-std=c++20', #* log4sp addition *#

# '-fno-exceptions',
'-fexceptions', #* log4sp addition *#
Expand All @@ -130,6 +130,10 @@ class ExtensionConfig(object):

'-fPIC', #* log4sp addition *#
'-g0', #* log4sp addition *#
'-flto=auto', #* log4sp addition *#
'-funroll-loops', #* log4sp addition *#
'-floop-interchange', #* log4sp addition *#
'-finline-functions' #* log4sp addition *#
]
cxx.linkflags += ['-m32']

Expand Down Expand Up @@ -180,6 +184,8 @@ class ExtensionConfig(object):
'/GR', #* log4sp addition *#

'/TP',
'/utf-8', #* log4sp addition *#
'/GL', #* log4sp addition *#
]
cxx.linkflags += [
'/MACHINE:X86',
Expand Down
9 changes: 4 additions & 5 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ projectName = 'log4sp'
# smsdk_ext.cpp will be automatically added later
sourceFiles = [
'src/extension.cpp',
'src/log4sp/common.cpp',
'src/log4sp/sink_registry.cpp',
'src/natives/common.cpp',
'src/natives/logger.cpp',
'src/natives/sinks/sink.cpp',
'src/natives/sinks/server_console_sink.cpp',
'src/natives/sinks/base_file_sink.cpp',
'src/natives/sinks/rorating_file_sink.cpp',
'src/natives/sinks/daily_file_sink.cpp',
'src/natives/sinks/client_chat_sink.cpp',
'src/natives/sinks/client_console_sink.cpp',
'src/natives/sinks/daily_file_sink.cpp',
'src/natives/sinks/rorating_file_sink.cpp',
'src/natives/sinks/server_console_sink.cpp',
]

###############
Expand Down
18 changes: 18 additions & 0 deletions PackageScript
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ folder_list = [
'addons/sourcemod/scripting/include',
'addons/sourcemod/scripting/include/log4sp',
'addons/sourcemod/scripting/include/log4sp/sinks',
'addons/sourcemod/scripting/include/log4sp_no_ext',
'addons/sourcemod/scripting/include/log4sp_no_ext/sinks',
#'addons/sourcemod/gamedata',
#'addons/sourcemod/configs',
]
Expand Down Expand Up @@ -50,6 +52,22 @@ CopyFiles('sourcemod/scripting/include/log4sp/sinks', 'addons/sourcemod/scriptin
'client_console_sink.inc'
]
)
CopyFiles('sourcemod/scripting/include/log4sp_no_ext', 'addons/sourcemod/scripting/include/log4sp_no_ext',
[
'common.inc',
'logger.inc'
]
)
CopyFiles('sourcemod/scripting/include/log4sp_no_ext/sinks', 'addons/sourcemod/scripting/include/log4sp_no_ext/sinks',
[
'sink.inc',
'server_console_sink.inc',
'base_file_sink.inc',
'rotating_file_sink.inc',
'daily_file_sink.inc',
'client_console_sink.inc'
]
)

# GameData files
#CopyFiles('gamedata', 'addons/sourcemod/gamedata',
Expand Down
12 changes: 5 additions & 7 deletions extern/spdlog/include/spdlog/async_logger-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ SPDLOG_LOGGER_CATCH(msg.source)
}

// send flush request to the thread pool
SPDLOG_INLINE void spdlog::async_logger::flush_(){SPDLOG_TRY{auto pool_ptr = thread_pool_.lock();
if (!pool_ptr) {
SPDLOG_INLINE void spdlog::async_logger::flush_(){
SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){
pool_ptr->post_flush(shared_from_this(), overflow_policy_);
}
else {
throw_spdlog_ex("async flush: thread pool doesn't exist anymore");
}

std::future<void> future = pool_ptr->post_flush(shared_from_this(), overflow_policy_);
// Wait for the flush operation to complete.
// This might throw exception if the flush message get dropped because of overflow.
future.get();
}
SPDLOG_LOGGER_CATCH(source_loc())
}
Expand Down
24 changes: 10 additions & 14 deletions extern/spdlog/include/spdlog/async_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,18 @@

#include <spdlog/logger.h>

namespace spdlog {
//* Log4sp customization *//
#include <spdlog/details/backend_worker.h>

// Async overflow policy - block by default.
enum class async_overflow_policy {
block, // Block until message can be enqueued
overrun_oldest, // Discard oldest message in the queue if full when trying to
// add new item.
discard_new // Discard new message if the queue is full when trying to add new item.
};
namespace spdlog {

namespace details {
class thread_pool;
}

class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_logger>,
public logger {
friend class details::thread_pool;

//* Log4sp customization *//
class SPDLOG_API async_logger final : public logger,
public details::backend_worker {
public:
template <typename It>
async_logger(std::string logger_name,
Expand All @@ -60,8 +54,10 @@ class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_
protected:
void sink_it_(const details::log_msg &msg) override;
void flush_() override;
void backend_sink_it_(const details::log_msg &incoming_log_msg);
void backend_flush_();

//* Log4sp customization *//
void backend_sink_it_(const details::log_msg &incoming_log_msg) override;
void backend_flush_() override;

private:
std::weak_ptr<details::thread_pool> thread_pool_;
Expand Down
29 changes: 29 additions & 0 deletions extern/spdlog/include/spdlog/details/backend_worker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)

#pragma once

//* Log4sp customization *//

namespace spdlog {
// Async overflow policy - block by default.
enum class async_overflow_policy {
block, // Block until message can be enqueued
overrun_oldest, // Discard oldest message in the queue if full when trying to
// add new item.
discard_new // Discard new message if the queue is full when trying to add new item.
};

namespace details {
class thread_pool;

class backend_worker : public std::enable_shared_from_this<backend_worker> {
friend class thread_pool;

protected:
virtual void backend_sink_it_(const details::log_msg &msg) = 0;
virtual void backend_flush_() = 0;
};

} // namespace details
} // namespace spdlog
3 changes: 2 additions & 1 deletion extern/spdlog/include/spdlog/details/file_helper-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ SPDLOG_INLINE void file_helper::write(const memory_buf_t &buf) {
if (fd_ == nullptr) return;
size_t msg_size = buf.size();
auto data = buf.data();
if (std::fwrite(data, 1, msg_size, fd_) != msg_size) {

if (!details::os::fwrite_bytes(data, msg_size, fd_)) {
throw_spdlog_ex("Failed writing to file " + os::filename_to_str(filename_), errno);
}
}
Expand Down
6 changes: 3 additions & 3 deletions extern/spdlog/include/spdlog/details/mpmc_blocking_q.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,19 @@ class mpmc_blocking_queue {
#endif

size_t overrun_counter() {
std::unique_lock<std::mutex> lock(queue_mutex_);
std::lock_guard<std::mutex> lock(queue_mutex_);
return q_.overrun_counter();
}

size_t discard_counter() { return discard_counter_.load(std::memory_order_relaxed); }

size_t size() {
std::unique_lock<std::mutex> lock(queue_mutex_);
std::lock_guard<std::mutex> lock(queue_mutex_);
return q_.size();
}

void reset_overrun_counter() {
std::unique_lock<std::mutex> lock(queue_mutex_);
std::lock_guard<std::mutex> lock(queue_mutex_);
q_.reset_overrun_counter();
}

Expand Down
18 changes: 15 additions & 3 deletions extern/spdlog/include/spdlog/details/os-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,12 @@ SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {

// find the size to allocate for the result buffer
int result_size =
::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, NULL, 0);
::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, NULL, 0);

if (result_size > 0) {
target.resize(result_size);
result_size = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size,
target.data(), result_size);
result_size = ::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, target.data(),
result_size);
if (result_size > 0) {
assert(result_size == target.size());
return;
Expand Down Expand Up @@ -589,6 +589,18 @@ SPDLOG_INLINE bool fsync(FILE *fp) {
#endif
}

// Do non-locking fwrite if possible by the os or use the regular locking fwrite
// Return true on success.
SPDLOG_INLINE bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp) {
#if defined(_WIN32) && defined(SPDLOG_FWRITE_UNLOCKED)
return _fwrite_nolock(ptr, 1, n_bytes, fp) == n_bytes;
#elif defined(SPDLOG_FWRITE_UNLOCKED)
return ::fwrite_unlocked(ptr, 1, n_bytes, fp) == n_bytes;
#else
return std::fwrite(ptr, 1, n_bytes, fp) == n_bytes;
#endif
}

} // namespace os
} // namespace details
} // namespace spdlog
4 changes: 4 additions & 0 deletions extern/spdlog/include/spdlog/details/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ SPDLOG_API std::string getenv(const char *field);
// Return true on success.
SPDLOG_API bool fsync(FILE *fp);

// Do non-locking fwrite if possible by the os or use the regular locking fwrite
// Return true on success.
SPDLOG_API bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp);

} // namespace os
} // namespace details
} // namespace spdlog
Expand Down
13 changes: 4 additions & 9 deletions extern/spdlog/include/spdlog/details/thread_pool-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,16 @@ SPDLOG_INLINE thread_pool::~thread_pool() {
SPDLOG_CATCH_STD
}

void SPDLOG_INLINE thread_pool::post_log(async_logger_ptr &&worker_ptr,
void SPDLOG_INLINE thread_pool::post_log(backend_worker_ptr &&worker_ptr,
const details::log_msg &msg,
async_overflow_policy overflow_policy) {
async_msg async_m(std::move(worker_ptr), async_msg_type::log, msg);
post_async_msg_(std::move(async_m), overflow_policy);
}

std::future<void> SPDLOG_INLINE thread_pool::post_flush(async_logger_ptr &&worker_ptr,
async_overflow_policy overflow_policy) {
std::promise<void> promise;
std::future<void> future = promise.get_future();
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush, std::move(promise)),
overflow_policy);
return future;
void SPDLOG_INLINE thread_pool::post_flush(backend_worker_ptr &&worker_ptr,
async_overflow_policy overflow_policy) {
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
}

size_t SPDLOG_INLINE thread_pool::overrun_counter() { return q_.overrun_counter(); }
Expand Down Expand Up @@ -112,7 +108,6 @@ bool SPDLOG_INLINE thread_pool::process_next_msg_() {
}
case async_msg_type::flush: {
incoming_async_msg.worker_ptr->backend_flush_();
incoming_async_msg.flush_promise.set_value();
return true;
}

Expand Down
30 changes: 10 additions & 20 deletions extern/spdlog/include/spdlog/details/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@

#include <chrono>
#include <functional>
#include <future>
#include <memory>
#include <thread>
#include <vector>

namespace spdlog {
class async_logger;

namespace details {
//* Log4sp customization *//
class backend_worker;

using async_logger_ptr = std::shared_ptr<spdlog::async_logger>;
using backend_worker_ptr = std::shared_ptr<backend_worker>;

enum class async_msg_type { log, flush, terminate };

// Async msg to move to/from the queue
// Movable only. should never be copied
struct async_msg : log_msg_buffer {
async_msg_type msg_type{async_msg_type::log};
async_logger_ptr worker_ptr;
std::promise<void> flush_promise;
backend_worker_ptr worker_ptr;

async_msg() = default;
~async_msg() = default;
Expand All @@ -55,23 +54,15 @@ struct async_msg : log_msg_buffer {
#endif

// construct from log_msg with given type
async_msg(async_logger_ptr &&worker, async_msg_type the_type, const details::log_msg &m)
async_msg(backend_worker_ptr &&worker, async_msg_type the_type, const details::log_msg &m)
: log_msg_buffer{m},
msg_type{the_type},
worker_ptr{std::move(worker)},
flush_promise{} {}
worker_ptr{std::move(worker)} {}

async_msg(async_logger_ptr &&worker, async_msg_type the_type)
async_msg(backend_worker_ptr &&worker, async_msg_type the_type)
: log_msg_buffer{},
msg_type{the_type},
worker_ptr{std::move(worker)},
flush_promise{} {}

async_msg(async_logger_ptr &&worker, async_msg_type the_type, std::promise<void> &&promise)
: log_msg_buffer{},
msg_type{the_type},
worker_ptr{std::move(worker)},
flush_promise{std::move(promise)} {}
worker_ptr{std::move(worker)} {}

explicit async_msg(async_msg_type the_type)
: async_msg{nullptr, the_type} {}
Expand All @@ -95,11 +86,10 @@ class SPDLOG_API thread_pool {
thread_pool(const thread_pool &) = delete;
thread_pool &operator=(thread_pool &&) = delete;

void post_log(async_logger_ptr &&worker_ptr,
void post_log(backend_worker_ptr &&worker_ptr,
const details::log_msg &msg,
async_overflow_policy overflow_policy);
std::future<void> post_flush(async_logger_ptr &&worker_ptr,
async_overflow_policy overflow_policy);
void post_flush(backend_worker_ptr &&worker_ptr, async_overflow_policy overflow_policy);
size_t overrun_counter();
void reset_overrun_counter();
size_t discard_counter();
Expand Down
Loading

0 comments on commit 4287618

Please sign in to comment.