mirror of https://github.com/gabime/spdlog.git
Implements shared library compatible global set_default_logger.
The key difference is that registry::instance is moved to a cpp when compiling the library.pull/2200/head
parent
0c611af552
commit
9f87c566bd
@ -0,0 +1,21 @@
|
||||
//
|
||||
// Copyright(c) 2021
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
#include "mylibrary.h"
|
||||
|
||||
int main(int, char *[])
|
||||
{
|
||||
auto new_logger = spdlog::basic_logger_mt("library_example", "logs/library_example.txt", true);
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
|
||||
spdlog::set_default_logger(new_logger);
|
||||
#ifndef SPDLOG_SHARED_LIB
|
||||
lib::set_logger(new_logger);
|
||||
#endif
|
||||
|
||||
spdlog::info("This message is from the base application");
|
||||
lib::test();
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Copyright(c) 2021
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#include "mylibrary.h"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace lib
|
||||
{
|
||||
const std::string logger_name = "example";
|
||||
|
||||
void set_logger(const std::shared_ptr<spdlog::logger>& logger)
|
||||
{
|
||||
spdlog::set_default_logger(logger);
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
spdlog::info("This message is from the shared library.");
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright(c) 2021
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#ifdef _WIN32
|
||||
#define LIB_EXPORT __declspec(dllexport)
|
||||
#else // !defined(_WIN32)
|
||||
#define LIB_EXPORT
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <spdlog/logger.h>
|
||||
|
||||
namespace lib
|
||||
{
|
||||
LIB_EXPORT void set_logger(const std::shared_ptr<spdlog::logger>& logger);
|
||||
|
||||
LIB_EXPORT void test();
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#ifndef SPDLOG_COMPILED_LIB
|
||||
# error Please define SPDLOG_COMPILED_LIB to compile this file.
|
||||
#endif
|
||||
|
||||
#include <spdlog/details/registry.h>
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
registry ®istry::instance()
|
||||
{
|
||||
static registry s_instance;
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue