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:
2018-11-23 17:53:43 +00:00
parent 491dd27ebf
commit b90445de4a
35 changed files with 1163 additions and 1364 deletions

View File

@@ -40,10 +40,10 @@
#include <fstream>
#include <iostream>
#include <string>
#include "textstream.h"
#include "logmanipulators.h"
#include "textstream/textstream.h"
#include "filelog.h"
#include "log/log.h"
namespace Winix
@@ -51,67 +51,51 @@ namespace Winix
class Log
class Log : public PT::Log
{
public:
Log();
~Log();
virtual ~Log();
void SetLogBuffer(TextStream<std::wstring> * buffer);
virtual void SetDependency(Log * log);
void SetFileLog(FileLog * file_log);
FileLog * GetFileLog();
virtual void SetMaxRequests(int max_requests);
void SetDependency(Log * log);
virtual Log & operator<<(const void * s);
virtual Log & operator<<(const char * s);
virtual Log & operator<<(const std::string * s);
virtual Log & operator<<(const std::string & s);
virtual Log & operator<<(const wchar_t * s);
virtual Log & operator<<(const std::wstring * s);
virtual Log & operator<<(const std::wstring & s);
virtual Log & operator<<(int s);
virtual Log & operator<<(long s);
virtual Log & operator<<(char s);
virtual Log & operator<<(wchar_t s);
virtual Log & operator<<(size_t s);
virtual Log & operator<<(double s);
virtual Log & operator<<(const PT::Space & space);
virtual Log & operator<<(LogManipulators m);
virtual Log & operator<<(const PT::Date & date);
void Init(int max_requests);
Log & operator<<(const void * s);
Log & operator<<(const char * s);
Log & operator<<(const std::string * s);
Log & operator<<(const std::string & s);
Log & operator<<(const wchar_t * s);
Log & operator<<(const std::wstring * s);
Log & operator<<(const std::wstring & s);
Log & operator<<(int s);
Log & operator<<(long s);
Log & operator<<(char s);
Log & operator<<(wchar_t s);
Log & operator<<(size_t s);
Log & operator<<(double s);
Log & operator<<(const PT::Space & space);
Log & operator<<(LogManipulators m);
Log & operator<<(const PT::Date & date);
void PrintDate(const PT::Date & date);
virtual void PrintDate(const PT::Date & date);
template<typename char_type, size_t stack_size, size_t heap_block_size>
Log & operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
template<class StringType>
void LogString(const StringType & value, size_t max_size);
void LogBinary(const char * blob, size_t blob_len);
void LogBinary(const std::string & blob);
void SystemErr(int err);
void SaveLog();
void SaveLogAndClear();
virtual Log & LogString(const std::string & value, size_t max_size);
virtual Log & LogString(const std::wstring & value, size_t max_size);
virtual Log & LogBinary(const char * blob, size_t blob_len);
virtual Log & LogBinary(const std::string & blob);
virtual Log & SystemErr(int err);
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
// current level set by a modifier (e.g. log << log3)
int current_level;
// current request for logging
// starts from zero and incremented after logendrequest modifier
int request;
@@ -119,51 +103,18 @@ 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;
// how many lines can be in the config buffer
// default: 5000
int max_lines;
FileLog * file_log;
char GetHEXdigit(unsigned char c);
void ToHEX(char * buf, unsigned char c);
};
template<class StringType>
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 <= file_log->get_log_level() && buffer )
{
for(size_t i=0 ; i<min_size ; ++i)
{
if( value[i] < 32 )
(*buffer) << '.';
else
(*buffer) << value[i];
}
}
}
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 <= file_log->get_log_level() && buffer )
(*buffer) << buf;
return *this;
PT::Log::operator<<(buf);
return *this;
}