updated to the new pikotools api - we have a logger for morm and ezc
pikotools has now Log and FileLog classes which are base classes for winix Log and FileLog classes git-svn-id: svn://ttmath.org/publicrep/winix/branches/0.7.x@1151 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2018, Tomasz Sowa
|
||||
* Copyright (c) 2018, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -47,8 +47,6 @@ namespace Winix
|
||||
|
||||
FileLog::FileLog()
|
||||
{
|
||||
log_stdout = false;
|
||||
log_file_open = false;
|
||||
time_zones = nullptr;
|
||||
synchro = nullptr;
|
||||
log_time_zone_id = 0;
|
||||
@@ -68,13 +66,8 @@ void FileLog::set_synchro(Synchro * synchro)
|
||||
|
||||
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;
|
||||
PT::FileLog::init(log_file, log_stdout, log_level, save_each_line);
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -122,57 +115,15 @@ PT::Date FileLog::get_local_date(const PT::Date & date)
|
||||
|
||||
|
||||
|
||||
void FileLog::open_file()
|
||||
bool FileLog::synchro_lock()
|
||||
{
|
||||
if( !log_file.empty() )
|
||||
{
|
||||
file.open( log_file.c_str(), std::ios_base::out | std::ios_base::app );
|
||||
log_file_open = true;
|
||||
}
|
||||
return synchro->Lock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FileLog::save_log(TextStream<std::wstring> * buffer)
|
||||
void FileLog::synchro_unlock()
|
||||
{
|
||||
if( buffer->Str().empty() )
|
||||
return;
|
||||
|
||||
if( synchro )
|
||||
{
|
||||
synchro->Lock();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( log_stdout )
|
||||
PT::WideToUTF8(buffer->Str(), std::cout);
|
||||
|
||||
if( log_file.empty() )
|
||||
return;
|
||||
|
||||
if( !log_file_open || !file )
|
||||
{
|
||||
file.close();
|
||||
file.clear();
|
||||
|
||||
open_file();
|
||||
|
||||
if( !file )
|
||||
return;
|
||||
}
|
||||
|
||||
PT::WideToUTF8(buffer->Str(), file);
|
||||
file.flush();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
|
||||
if( synchro )
|
||||
{
|
||||
synchro->Unlock();
|
||||
}
|
||||
synchro->Unlock();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user