add WINIX_SAVE_FILELOG plugin message

This commit is contained in:
Tomasz Sowa 2022-09-01 07:34:10 +02:00
parent e09a93bd72
commit bff435db9a
4 changed files with 40 additions and 20 deletions

View File

@ -70,6 +70,7 @@ App::App()
file_log.set_synchro(&synchro);
file_log.set_time_zones(&system.time_zones);
// file_log.set_plugin(...) is called later, when a plugin object is initialized
log.set_log_buffer(&log_buffer);
log.set_file_log(&file_log);
@ -116,6 +117,9 @@ App::App()
plugin.SetSessionManager(&session_manager);
plugin.SetWinixRequest(&winix_request);
// now we can set the plugin in the file_log
file_log.set_plugin(&plugin);
functions.set_dependency(&winix_request);
// functions.set_config(&config);
// functions.set_file_log(&file_log);

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2018-2019, Tomasz Sowa
* Copyright (c) 2018-2022, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -37,7 +37,7 @@
#include <string.h>
#include "utf8/utf8.h"
#include "timezones.h"
#include "plugin.h"
namespace Winix
@ -49,6 +49,7 @@ FileLog::FileLog()
{
time_zones = nullptr;
synchro = nullptr;
plugin = nullptr;
log_time_zone_id = 0;
}
@ -64,6 +65,12 @@ void FileLog::set_synchro(Synchro * synchro)
}
void FileLog::set_plugin(Plugin * plugin)
{
this->plugin = plugin;
}
void FileLog::init(const std::wstring & log_file, bool log_stdout, int log_level, bool save_each_line, size_t log_time_zone_id)
{
pt::FileLog::init(log_file, log_stdout, log_level, save_each_line);
@ -116,19 +123,23 @@ pt::Date FileLog::get_local_date(const pt::Date & date)
bool FileLog::synchro_lock()
void FileLog::save_log(pt::WTextStream * buffer)
{
return synchro->Lock();
if( !buffer->empty() )
{
Lock lock(synchro);
pt::FileLog::save_log(buffer);
// at the beginning when winix starts the plugin pointer is null
// this plugin is set after the plugin object is initialized
if( plugin )
{
plugin->Call(WINIX_SAVE_FILELOG, buffer);
}
}
}
void FileLog::synchro_unlock()
{
synchro->Unlock();
}
} // namespace Winix

View File

@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2018-2021, Tomasz Sowa
* Copyright (c) 2018-2022, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -47,7 +47,7 @@
namespace Winix
{
class TimeZones;
class Plugin;
class FileLog : public pt::FileLog
{
@ -57,6 +57,7 @@ public:
virtual ~FileLog();
void set_synchro(Synchro * synchro);
void set_plugin(Plugin * plugin);
// using pt::FileLog::init to suppress clang warning:
// warning: 'Winix::FileLog::init' hides overloaded virtual function [-Woverloaded-virtual]
@ -70,6 +71,8 @@ public:
int get_log_level();
bool should_save_each_line();
void save_log(pt::WTextStream * buffer);
protected:
@ -77,12 +80,8 @@ protected:
size_t log_time_zone_id;
TimeZones * time_zones;
Synchro * synchro;
virtual bool synchro_lock();
virtual void synchro_unlock();
Plugin * plugin; // can be null (only at the beginning when winix starts)
};

View File

@ -303,14 +303,20 @@ namespace Winix
// http headers (without cookies) were created and are ready to send
// here you can make some changes to them
// in p1 you have a pointer to the PT::Space (Request::out_headers)
// in p1 you have a pointer to the pt::Space (Request::out_headers)
#define WINIX_PREPARE_TO_SEND_HTTP_HEADERS 31070
// http cookies were created and are ready to send
// here you can make some changes to them
// in p1 you have a pointer to the PT::Space (Request::out_cookies)
// in p1 you have a pointer to the pt::Space (Request::out_cookies)
#define WINIX_PREPARE_TO_SEND_HTTP_COOKIES 31080
// a file log was saved
// in p1 you have a pointer to the pt::WTextStream buffer
// this can be called from a different thread but with locking
#define WINIX_SAVE_FILELOG 31090
/*
messages sent from other threads