some work in the new api:

- log_level and save_each_line moved from Log to FileLog
- other fixes in loggers
- DirContainer from Dirs and LoadAvg had no dependencies set




git-svn-id: svn://ttmath.org/publicrep/winix/branches/0.7.x@1148 e52654a7-88a9-db11-a3e9-0013d4bc506e
pull/3/head
Tomasz Sowa 4 years ago
parent 89d303f375
commit 491dd27ebf

File diff suppressed because one or more lines are too long

@ -65,9 +65,11 @@ App::App()
last_sessions_save = std::time(0);
fcgi_socket = -1;
file_log.set_synchro(&synchro);
file_log.set_time_zones(&system.time_zones);
log.SetLogBuffer(&log_buffer);
log.SetFileLog(&file_log);
log.Init(config.log_level, config.log_save_each_line, config.log_request);
// objects dependency for main thread
winix_base.set_config(&config);
@ -90,6 +92,7 @@ App::App()
config.SetFileLog(&file_log);
config.SetLogBuffer(&log_buffer);
// temporary there is only one request
@ -159,17 +162,20 @@ App::App()
void App::InitFileLog()
void App::InitLoggers()
{
file_log.set_synchro(&synchro);
file_log.set_time_zones(&system.time_zones);
file_log.init(config.log_file, config.log_stdout, config.log_time_zone_id);
file_log.init(config.log_file, config.log_stdout, config.log_level, config.log_save_each_line, config.log_time_zone_id);
log.Init(config.log_request);
}
log.SetFileLog(&file_log);
log.Init(config.log_level, config.log_save_each_line, config.log_request);
Log & App::GetMainLog()
{
return log;
}
void App::InitPlugins()
{
plugin.LoadPlugins(config.plugins_dir, config.plugin_file);

@ -75,7 +75,8 @@ public:
bool InitFCGI();
bool DropPrivileges();
void InitFileLog();
void InitLoggers();
Log & GetMainLog();
void InitPlugins();
bool Init();
void Start();
@ -131,9 +132,6 @@ public:
FileLog file_log;
private:
@ -190,6 +188,9 @@ private:
// logger only for App object
Log log;
// file logger, one object for every Log objects
FileLog file_log;
bool InitFCGI(char * sock, char * sock_user, char * sock_group);
bool InitFCGIChmodChownSocket(char * sock, char * sock_user, char * sock_group);
bool DropPrivileges(char * user, char * group);

@ -54,7 +54,13 @@ void Config::SetFileLog(FileLog * file_log)
log.SetFileLog(file_log);
// the config is not read yet so we put some constants here
log.Init(3, false, 1);
log.Init(1);
}
void Config::SetLogBuffer(TextStream<std::wstring> * log_buffer)
{
log.SetLogBuffer(log_buffer);
}

@ -819,7 +819,10 @@ public:
// raw access to the config
PT::Space space;
void SetFileLog(FileLog * file_log);
void SetLogBuffer(TextStream<std::wstring> * log_buffer);
private:

@ -60,6 +60,13 @@ void Dirs::SetNotify(Notify * pnotify)
}
void Dirs::set_dependency(WinixModel * winix_model)
{
WinixModel::set_dependency(winix_model);
dir_tab.set_dependency(winix_model);
}
void Dirs::Clear()
{
dir_tab.Clear();

@ -69,6 +69,8 @@ public:
void SetDb(Db * pdb);
void SetNotify(Notify * pnotify);
void set_dependency(WinixModel * winix_model);
// these methods return false if there is no such a dir
bool IsDir(long dir_id);
bool GetDirChilds(long parent_id, std::vector<Item*> & childs_tab); // !! zamienic na GetChilds()

@ -66,23 +66,38 @@ void FileLog::set_synchro(Synchro * synchro)
}
void FileLog::init(const std::wstring & log_file, bool log_stdout, size_t log_time_zone_id)
void FileLog::init(const std::wstring & log_file, bool log_stdout, int log_level, bool save_each_line, size_t log_time_zone_id)
{
this->log_stdout = log_stdout;
this->log_time_zone_id = log_time_zone_id;
this->log_level = log_level;
this->save_each_line = save_each_line;
PT::WideToUTF8(log_file, this->log_file);
// don't open the file here
// because it would be created with the root as an owner
}
void FileLog::set_time_zones(TimeZones * time_zones)
{
this->time_zones = time_zones;
}
int FileLog::get_log_level()
{
return log_level;
}
bool FileLog::should_save_each_line()
{
return save_each_line;
}
PT::Date FileLog::get_local_date(const PT::Date & date)
{
if( time_zones )

@ -58,12 +58,14 @@ public:
void set_synchro(Synchro * synchro);
void init(const std::wstring & log_file, bool log_stdout, size_t log_time_zone_id);
void init(const std::wstring & log_file, bool log_stdout, int log_level, bool save_each_line, size_t log_time_zone_id);
void save_log(TextStream<std::wstring> * buffer);
void set_time_zones(TimeZones * time_zones);
PT::Date get_local_date(const PT::Date & date);
int get_log_level();
bool should_save_each_line();
private:
@ -83,6 +85,13 @@ private:
Synchro * synchro;
// log lovel from the config file
int log_level;
// whether to save each line (for debug)
bool save_each_line;
void open_file();
};

@ -52,7 +52,7 @@ namespace Winix
class LoadAvg : WinixBase
class LoadAvg : public WinixBase
{
public:
LoadAvg();

@ -46,14 +46,12 @@ namespace Winix
Log::Log()
{
log_level = 1;
current_level = 100; // nothing to log (call Init() first)
request = 0;
max_requests = 1;
lines = 0;
max_lines = 5000;
file_log = nullptr;
save_each_line = false;
buffer = nullptr;
}
@ -89,17 +87,9 @@ void Log::SetDependency(Log * log)
}
int Log::LogLevel()
{
return log_level;
}
void Log::Init(int log_level, bool save_each_line, int max_requests)
void Log::Init(int max_requests)
{
this->log_level = log_level;
this->save_each_line = save_each_line;
this->max_requests = max_requests;
}
@ -121,7 +111,7 @@ void Log::PrintDate(const PT::Date & date)
Log & Log::operator<<(const void * s)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << s;
}
@ -133,7 +123,7 @@ Log & Log::operator<<(const void * s)
Log & Log::operator<<(const char * s)
{
if( current_level <= log_level && buffer && s )
if( current_level <= file_log->get_log_level() && buffer && s )
{
(*buffer) << s;
}
@ -145,7 +135,7 @@ return *this;
Log & Log::operator<<(const std::string & s)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << s;
}
@ -157,7 +147,7 @@ Log & Log::operator<<(const std::string & s)
Log & Log::operator<<(const std::string * s)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << *s;
}
@ -172,7 +162,7 @@ Log & Log::operator<<(const std::string * s)
Log & Log::operator<<(const wchar_t * s)
{
if( current_level <= log_level && buffer && s )
if( current_level <= file_log->get_log_level() && buffer && s )
{
(*buffer) << s;
}
@ -184,7 +174,7 @@ return *this;
Log & Log::operator<<(const std::wstring & s)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << s;
}
@ -196,7 +186,7 @@ Log & Log::operator<<(const std::wstring & s)
Log & Log::operator<<(const std::wstring * s)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << *s;
}
@ -210,7 +200,7 @@ Log & Log::operator<<(const std::wstring * s)
Log & Log::operator<<(int s)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << s;
}
@ -222,7 +212,7 @@ Log & Log::operator<<(int s)
Log & Log::operator<<(long s)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << s;
}
@ -235,7 +225,7 @@ Log & Log::operator<<(long s)
Log & Log::operator<<(char s)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << s;
}
@ -246,7 +236,7 @@ Log & Log::operator<<(char s)
Log & Log::operator<<(wchar_t s)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << s;
}
@ -257,7 +247,7 @@ Log & Log::operator<<(wchar_t s)
Log & Log::operator<<(size_t s)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << s;
}
@ -269,7 +259,7 @@ Log & Log::operator<<(size_t s)
Log & Log::operator<<(double s)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << s;
}
@ -281,7 +271,7 @@ Log & Log::operator<<(double s)
Log & Log::operator<<(const PT::Space & s)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << s;
}
@ -293,7 +283,7 @@ return *this;
Log & Log::operator<<(const PT::Date & date)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << date;
}
@ -308,12 +298,12 @@ Log & Log::operator<<(LogManipulators m)
switch(m)
{
case logend:
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
(*buffer) << '\n';
lines += 1;
if( save_each_line )
if( file_log->should_save_each_line() )
SaveLogAndClear();
}
break;
@ -455,7 +445,7 @@ void Log::SaveLogAndClear()
void Log::SaveLog()
{
if( file_log && buffer )
if( buffer )
{
file_log->save_log(buffer);
}

@ -65,7 +65,7 @@ public:
void SetDependency(Log * log);
void Init(int log_level, bool save_each_line, int max_requests);
void Init(int max_requests);
Log & operator<<(const void * s);
Log & operator<<(const char * s);
@ -101,7 +101,6 @@ public:
void SaveLog();
void SaveLogAndClear();
int LogLevel();
@ -110,9 +109,6 @@ private:
// buffer for the log
TextStream<std::wstring> * buffer; // IMPROVE ME this buffer should be a common buffer for all objects for a one thread
// log lovel from the config file
int log_level;
// current level set by a modifier (e.g. log << log3)
int current_level;
@ -123,6 +119,8 @@ private:
// how many request to save at once
int max_requests;
// IMPROVE ME now we don't know how many lines there are in the buffer as the buffer can be used by other Logs
// how many lines there are in the buffer
int lines;
@ -130,8 +128,6 @@ private:
// default: 5000
int max_lines;
// whether to save each line (for debug)
bool save_each_line;
FileLog * file_log;
@ -147,7 +143,7 @@ void Log::LogString(const StringType & value, size_t max_size)
{
size_t min_size = value.size() < max_size ? value.size() : max_size;
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
{
for(size_t i=0 ; i<min_size ; ++i)
{
@ -164,7 +160,7 @@ size_t min_size = value.size() < max_size ? value.size() : max_size;
template<typename char_type, size_t stack_size, size_t heap_block_size>
Log & Log::operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf)
{
if( current_level <= log_level && buffer )
if( current_level <= file_log->get_log_level() && buffer )
(*buffer) << buf;
return *this;

@ -197,7 +197,7 @@ bool Plugin::SetDependency(PluginInfo & info)
info.plugin = this;
info.log.SetDependency(&log);
log.Init(config->log_level, config->log_save_each_line, config->log_request);
log.Init(config->log_request);
return res;
}

@ -83,9 +83,20 @@ void System::SetSessionManager(SessionManager * sm)
void System::set_dependency(WinixModel * winix_model)
{
WinixModel::set_dependency(winix_model);
dirs.set_dependency(this);
mounts.set_dependency(this);
users.set_dependency(this);
groups.set_dependency(this);
rebus.set_dependency(this);
load_avg.set_dependency(this);
notify.set_dependency(this);
image.set_dependency(this);
crypt.set_dependency(this);
thread_manager.set_dependency(this);
job.set_dependency(winix_model);
time_zones.set_dependency(winix_model);
WinixModel::set_dependency(winix_model);
}
@ -115,16 +126,13 @@ void System::ReadTimeZones()
void System::Init()
{
//thread_manager.SetSynchro(synchro);
thread_manager.set_dependency(this);
thread_manager.Init();
dirs.set_dependency(this);
dirs.SetDb(db);
dirs.SetCur(cur); // only one method is using cur, can be passed as a parameter to the method
dirs.SetNotify(&notify);
dirs.ReadDirs();
mounts.set_dependency(this);
mounts.SkipStaticDirs(config->dont_use_static_dirs);
mounts.SetDirs(&dirs);
mounts.SetDb(db);
@ -132,19 +140,16 @@ void System::Init()
mounts.CreateMounts();
mounts.ReadMounts();
users.set_dependency(this);
users.SetCur(cur);
users.SetSessionManager(session_manager);
users.ReadUsers(db);
groups.set_dependency(this);
groups.ReadGroups(db); // !! chwilowe przekazanie argumentu, db bedzie zmienione
rebus.set_dependency(this);
rebus.SetCur(cur);
rebus.Init();
notify.set_dependency(this);
notify.SetCur(cur);
//notify.SetConfig(config);
notify.SetUsers(&users);
@ -157,7 +162,8 @@ void System::Init()
image.SetSystem(this);
thread_manager.Add(&image, L"image");
crypt.set_dependency(this);
// SetSynchro will be called by ThreadManager itself
// job.ReadFromFile();

@ -79,7 +79,7 @@ void WinixBase::set_dependency(WinixBase * winix_base)
{
config = winix_base->config;
synchro = winix_base->synchro;
log.SetFileLog(winix_base->log.GetFileLog());
log.SetDependency(&winix_base->log);
}

@ -75,6 +75,7 @@ void WinixModel::set_dependency(WinixModel * winix_model)
{
WinixBase::set_dependency(winix_model);
model_connector = winix_model->model_connector;
plugin = winix_model->plugin;
}

@ -43,8 +43,7 @@
#include "core/app.h"
#include "core/version.h"
#include "utf8/utf8.h"
#include "core/filelog.h"
#include "core/log.h"
@ -159,10 +158,6 @@ using Winix::app;
std::srand(std::time(0));
Winix::TextStream<std::wstring> log_buffer;
Winix::Log log; // log only for main() function
log.SetLogBuffer(&log_buffer);
if( argv != 2 )
{
Winix::print_syntax();
@ -180,6 +175,9 @@ using Winix::app;
if( !app.config.ReadConfig(true, false) ) /* errors to stdout, stdout in not closed */
return 2;
Winix::Log & log = app.GetMainLog();
app.InitLoggers();
if( app.stdout_is_closed || app.config.demonize )
app.config.log_stdout = false;
@ -189,11 +187,6 @@ using Winix::app;
if( app.config.demonize && !app.Demonize() )
return 4;
app.InitFileLog();
log.SetFileLog(&app.file_log);
log.Init(app.config.log_level, app.config.log_save_each_line, app.config.log_request);
Winix::LogInfo(log, Winix::log3, "booting Winix", true, "");
if( !app.InitFCGI() )

@ -1184,8 +1184,8 @@ void Templates::set_dependency(WinixRequest * winix_request)
TemplatesFunctions::locale_filter.set_dependency(winix_request);
TemplatesFunctions::html_filter.set_dependency(winix_request);
log.SetDependency(&this->log);
log.Init(config->log_level, config->log_save_each_line, config->log_request);
TemplatesFunctions::log.SetDependency(&this->log);
TemplatesFunctions::log.Init(config->log_request);
plugin = winix_request->get_plugin();
}

Loading…
Cancel
Save