2017-08-08 13:53:47 +02:00
|
|
|
#include "Logger.h"
|
|
|
|
|
2018-10-26 20:06:12 +11:00
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
#include <spdlog/async.h>
|
2018-10-25 12:21:22 +11:00
|
|
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
|
|
|
#include <spdlog/sinks/daily_file_sink.h>
|
|
|
|
|
|
|
|
// #include <iostream>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
|
2018-08-29 21:40:59 +02:00
|
|
|
Logger::Logger()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Logger::~Logger()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Logger::setLogPath( const std::string& logPath )
|
|
|
|
{
|
|
|
|
m_logFile = logPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Logger::init()
|
|
|
|
{
|
2018-10-26 19:57:39 +11:00
|
|
|
spdlog::init_thread_pool( 8192, 1 );
|
2018-08-29 21:40:59 +02:00
|
|
|
|
2018-10-26 19:57:39 +11:00
|
|
|
auto stdout_sink = std::make_shared< spdlog::sinks::stdout_color_sink_mt >();
|
|
|
|
auto daily_sink = std::make_shared< spdlog::sinks::daily_file_sink_mt >( m_logFile + ".log", 0, 0 );
|
2018-10-25 12:21:22 +11:00
|
|
|
|
2018-10-26 19:57:39 +11:00
|
|
|
std::vector<spdlog::sink_ptr> sinks { stdout_sink, daily_sink };
|
|
|
|
|
|
|
|
auto logger = std::make_shared< spdlog::async_logger >( "logger", sinks.begin(), sinks.end(), spdlog::thread_pool(), spdlog::async_overflow_policy::block );
|
|
|
|
|
|
|
|
spdlog::register_logger( logger );
|
|
|
|
spdlog::set_pattern( "[%H:%M:%S.%e] [%^%l%$] %v" );
|
2018-10-25 12:21:22 +11:00
|
|
|
|
2018-10-25 15:39:36 +11:00
|
|
|
// always flush the log on criticial messages, otherwise it's done by libc
|
|
|
|
// see: https://github.com/gabime/spdlog/wiki/7.-Flush-policy
|
|
|
|
// nb: if the server crashes, log data can be missing from the file unless something logs critical just before it does
|
2018-10-26 19:57:39 +11:00
|
|
|
spdlog::flush_on( spdlog::level::critical );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Logger::Log( LoggingSeverity logSev, const std::string& text )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Logger::error( const std::string& text )
|
|
|
|
{
|
2018-10-25 23:50:18 +02:00
|
|
|
spdlog::get( "logger" )->error( text );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Logger::info( const std::string& text )
|
|
|
|
{
|
2018-10-25 23:50:18 +02:00
|
|
|
spdlog::get( "logger" )->info( text );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Logger::debug( const std::string& text )
|
|
|
|
{
|
2018-10-25 23:50:18 +02:00
|
|
|
spdlog::get( "logger" )->debug( text );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Logger::fatal( const std::string& text )
|
|
|
|
{
|
2018-10-25 23:50:18 +02:00
|
|
|
spdlog::get( "logger" )->critical( text );
|
2018-08-29 21:40:59 +02:00
|
|
|
}
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
|
2018-10-25 14:47:06 +02:00
|
|
|
}
|