89 lines
1.8 KiB
C++
89 lines
1.8 KiB
C++
|
|
#include "Logger.hh"
|
|||
|
|
|
|||
|
|
#include "LogRecord.hh"
|
|||
|
|
|
|||
|
|
#include <memory>
|
|||
|
|
|
|||
|
|
namespace logging {
|
|||
|
|
|
|||
|
|
Logger::Logger( Id idx_ , base::log_permit_flag permissons_, uint32_t on_counter ) :
|
|||
|
|
idx(idx_), log_permission(permissons_), handler(nullptr), on_counter(on_counter) {}
|
|||
|
|
|
|||
|
|
void Logger::fill_record( const char * message, std::size_t length,
|
|||
|
|
LogRecord & record) {
|
|||
|
|
|
|||
|
|
record.set_time( std::time( nullptr ) );
|
|||
|
|
record.set_message( message, length );
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//todo: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
|
|
|||
|
|
void Logger::log_critical( const char * message, std::size_t length ) {
|
|||
|
|
|
|||
|
|
if( handler && ( log_permission & base::on_critical_log ) ) {
|
|||
|
|
|
|||
|
|
Local<ILogHandler> local_handler(handler);
|
|||
|
|
|
|||
|
|
if(local_handler) {
|
|||
|
|
|
|||
|
|
LogRecord record( on_counter, base::hi_record_priority, idx );
|
|||
|
|
|
|||
|
|
fill_record( message, length, record );
|
|||
|
|
|
|||
|
|
local_handler->publish(record);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Logger::log_error( const char * message, std::size_t length ) {
|
|||
|
|
|
|||
|
|
if( handler && ( log_permission & base::on_error_log ) ) {
|
|||
|
|
|
|||
|
|
Local<ILogHandler> local_handler(handler);
|
|||
|
|
|
|||
|
|
if(local_handler) {
|
|||
|
|
|
|||
|
|
LogRecord record( on_counter, base::medium_record_priority, idx );
|
|||
|
|
|
|||
|
|
fill_record( message, length, record );
|
|||
|
|
|
|||
|
|
local_handler->publish(record);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Logger::log_information( const char * message, std::size_t length ) {
|
|||
|
|
|
|||
|
|
if( handler && ( log_permission & base::on_information_log ) ) {
|
|||
|
|
|
|||
|
|
Local<ILogHandler> local_handler(handler);
|
|||
|
|
|
|||
|
|
if(local_handler) {
|
|||
|
|
|
|||
|
|
LogRecord record( on_counter, base::low_record_priority, idx );
|
|||
|
|
|
|||
|
|
fill_record( message, length, record );
|
|||
|
|
|
|||
|
|
local_handler->publish(record);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Logger::add_handler( ResourceKeeper<ILogHandler> * h ) {
|
|||
|
|
|
|||
|
|
if( h )
|
|||
|
|
handler = h;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|