Fixed logging on Windows. Event log sink is still broken.
This commit is contained in:
1 parent
3060386a23
commit
ac3d1869cf
14 files changed
+73
-20
No files matched your search
@@ -28,9 +28,7 @@ namespace mbts
|
||||
{
|
||||
internal static class Logger
|
||||
{
|
||||
static on_crash_callback native_crash_callback = system_is_crashing;
|
||||
static Logger() {
|
||||
set_on_crash_handler(native_crash_callback);
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
@@ -44,11 +42,6 @@ namespace mbts
|
||||
Logger_log(level, system, message, file, line);
|
||||
}
|
||||
|
||||
// Log this message at most once per run
|
||||
public static void log_once_probably(Level level, Subsystem system, string message, [CallerFilePath] string file = "c#", [CallerLineNumber] int line = 0) {
|
||||
Logger_log_once(level, system, $"{message} [{file}:{line}]");
|
||||
}
|
||||
|
||||
public static void error(Subsystem system, string message, [CallerFilePath] string file = "C#", [CallerLineNumber] int line = 0) {
|
||||
log(Level.Error, system, message, file, line);
|
||||
}
|
||||
@@ -85,13 +78,8 @@ namespace mbts
|
||||
|
||||
[DllImport("spark_lib")]
|
||||
private static extern void Logger_log (Level level, Subsystem subsystem, string message, string file, int line);
|
||||
[DllImport("spark_lib")]
|
||||
private static extern void Logger_log_once(Level level, Subsystem subsystem, string message);
|
||||
|
||||
delegate void on_crash_callback([MarshalAs(UnmanagedType.LPStr)]string msg, [MarshalAs(UnmanagedType.LPStr)] string details);
|
||||
[DllImport("spark_lib")]
|
||||
private static extern on_crash_callback set_on_crash_handler(on_crash_callback handler);
|
||||
|
||||
public static void system_is_crashing(string message, object details) {
|
||||
OnSystemCrashing?.Invoke(message, details);
|
||||
}
|
||||
|
||||
@@ -10,11 +10,14 @@ namespace mbts.utils
|
||||
{
|
||||
[DllImport("spark_lib")]
|
||||
public static extern void provide_command_line(
|
||||
[MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)] string[] argv, int argc);
|
||||
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] string[] argv, int argc);
|
||||
|
||||
[DllImport("spark_lib")]
|
||||
public static extern int get_random_port();
|
||||
|
||||
[DllImport("spark_lib")]
|
||||
public static extern void init_spark_lib();
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern bool SetConsoleTitle(string lpConsoleTitle);
|
||||
}
|
||||
|
||||
@@ -117,6 +117,7 @@ set (SparkLib_Sources
|
||||
utils/SharedMemory.cpp
|
||||
utils/Dispatcher.cpp
|
||||
utils/Sqlite_utils.cpp
|
||||
utils/init_spark_lib.cpp
|
||||
|
||||
# security model
|
||||
security_model/SecurityHelper.cpp
|
||||
|
||||
@@ -7,11 +7,13 @@ namespace config {
|
||||
namespace internal {
|
||||
|
||||
struct ConfigLog::PImpl {
|
||||
PImpl() :
|
||||
PImpl()
|
||||
:
|
||||
print_errors(true),
|
||||
logger_hub("config_logger"),
|
||||
logger(logger_hub.make_logger())
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
bool print_errors;
|
||||
log::LoggerHub logger_hub;
|
||||
@@ -42,6 +44,11 @@ ConfigLog::ConfigLog() :
|
||||
me->logger_hub.config(cfg);
|
||||
}
|
||||
|
||||
void ConfigLog::start()
|
||||
{
|
||||
me->logger_hub.start();
|
||||
}
|
||||
|
||||
ConfigLog::~ConfigLog()
|
||||
{
|
||||
me->logger.mark_inactive();
|
||||
|
||||
@@ -30,7 +30,8 @@ public:
|
||||
void info(const std::string& msg);
|
||||
void error(const std::string& msg);
|
||||
void warning(const std::string& msg);
|
||||
|
||||
void start();
|
||||
|
||||
bool print_errors() const ;
|
||||
void set_print_errors(bool value) ;
|
||||
|
||||
|
||||
@@ -149,7 +149,8 @@ void ConfigurationState::initialize_defaults()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(_initialization_mutex);
|
||||
if (_is_initialized) return;
|
||||
|
||||
|
||||
_log.start();
|
||||
generate_all_config_proto();
|
||||
|
||||
std::shared_ptr<proto::Message> new_message(_prototype->New());
|
||||
|
||||
@@ -107,8 +107,10 @@ public:
|
||||
|
||||
~Logger()
|
||||
{
|
||||
#ifndef WIN32
|
||||
bts_assert(!_active);
|
||||
bts_assert(_wcursor == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,7 +49,8 @@ LoggerHub::LoggerHub(std::string const&logger_name)
|
||||
{
|
||||
LoggingConfig cfg ;
|
||||
config(cfg);
|
||||
me->worker = std::thread(std::bind(&LoggerHub::do_work,this));
|
||||
// we cannot launch the worker thread here because thread creation
|
||||
// is not possible during static initialization
|
||||
}
|
||||
|
||||
void LoggerHub::config(const LoggingConfig &cfg)
|
||||
@@ -82,10 +83,16 @@ void LoggerHub::config(const LoggingConfig &cfg)
|
||||
update_logger_queue_limits();
|
||||
}
|
||||
|
||||
void LoggerHub::start() {
|
||||
bts_assert(!me->worker.joinable());
|
||||
me->worker = std::thread(&LoggerHub::do_work, this);
|
||||
}
|
||||
|
||||
LoggerHub::~LoggerHub()
|
||||
{
|
||||
me->done=true;
|
||||
me->worker.join();
|
||||
if (me->worker.joinable())
|
||||
me->worker.join();
|
||||
}
|
||||
|
||||
Logger &LoggerHub::make_logger()
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
LoggerHub(std::string const& );
|
||||
~LoggerHub();
|
||||
void config(const LoggingConfig &cfg);
|
||||
void start();
|
||||
Logger &make_logger();
|
||||
|
||||
private:
|
||||
@@ -32,4 +33,5 @@ private:
|
||||
Filter get_base_filter() const;
|
||||
};
|
||||
|
||||
void start_logging_hub();
|
||||
}}
|
||||
@@ -30,6 +30,11 @@ typename M::const_iterator find_key(M const&m, typename M::mapped_type const &v)
|
||||
return m.end();
|
||||
}
|
||||
|
||||
void start_default_logging_thread()
|
||||
{
|
||||
_default_logger_hub.start();
|
||||
}
|
||||
|
||||
Filter get_filter (LoggingConfig &cfg,
|
||||
config::Logging::SinkConfig const&scfg)
|
||||
{
|
||||
@@ -143,5 +148,12 @@ LoggingConfigPoller::~LoggingConfigPoller ()
|
||||
_poller_thread.join();
|
||||
}
|
||||
|
||||
}}
|
||||
namespace interop {
|
||||
extern "C" BTS_EXPORT void Logger_log (int level, int subsystem, const char *message, const char *file, int line)
|
||||
{
|
||||
bts::log::_thread_logger.logger->enqueue(log::Subsystem{(uint8_t)subsystem},log::Level{(uint8_t)level},file,line,message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
@@ -41,6 +41,7 @@ struct LoggerHandle {
|
||||
extern thread_local LoggerHandle _thread_logger;
|
||||
void configure_logging(LoggingConfig const&cfg);
|
||||
void configure_logging(bts::config::Logging const&cfg);
|
||||
void start_default_logging_thread();
|
||||
|
||||
class LoggingConfigPoller {
|
||||
public:
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "init_spark_lib.h"
|
||||
#include "lib/logging/logging.h"
|
||||
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
void init_spark_lib()
|
||||
{
|
||||
log::start_default_logging_thread();
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "bts_export.h"
|
||||
|
||||
// this is needed because we cannot relly on static initialization do
|
||||
// work reliably in DLL's on Windows. See:
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx
|
||||
// for a list of restrictions
|
||||
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
|
||||
extern "C" BTS_EXPORT void init_spark_lib();
|
||||
|
||||
}}
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/logging.pb.h"
|
||||
#include "lib/config/protos/Executor.pb.h"
|
||||
#include "lib/utils/init_spark_lib.h"
|
||||
#include "setup/BootstrapActor.h"
|
||||
#include "fabric/Domain.h"
|
||||
#include "testing/catch_test_runner.h"
|
||||
@@ -17,6 +18,7 @@ int main( int argc, char*argv [] )
|
||||
if (argc > 1 && std::string(argv[1]) == "test")
|
||||
bts::run_tests(--argc, ++argv);
|
||||
else {
|
||||
utils::init_spark_lib();
|
||||
log::LoggingConfigPoller poller;
|
||||
auto executor_cfg = config::get<config::ExecutorCfg> ();
|
||||
|
||||
@@ -28,3 +30,4 @@ int main( int argc, char*argv [] )
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user