68 lines
1.5 KiB
C++
68 lines
1.5 KiB
C++
/*
|
|
* MemoryLogHandler.h
|
|
*
|
|
* Created on: 24 àïð. 2020 ã.
|
|
* Author: AAM
|
|
*/
|
|
|
|
#ifndef LOGGING_MEMORYLOGHANDLER_H_
|
|
#define LOGGING_MEMORYLOGHANDLER_H_
|
|
|
|
#include <memory_resource>
|
|
|
|
#include <map>
|
|
#include <deque>
|
|
#include <vector>
|
|
|
|
#include <functional>
|
|
#include <mutex>
|
|
|
|
#include "ILogHandler.hh"
|
|
#include "StorageManager.hh"
|
|
|
|
namespace logging {
|
|
|
|
class MemoryLogHandler : public ILogHandler {
|
|
public:
|
|
enum ACCUMULATION_POLICY {
|
|
RESTRICTIVE = 0,
|
|
EXPANSION = 1
|
|
};
|
|
|
|
private:
|
|
std::size_t records_balance;
|
|
std::size_t records_capacity;
|
|
|
|
ACCUMULATION_POLICY accum_policy;
|
|
|
|
std::mutex lock;
|
|
|
|
typedef std::vector< char, std::pmr::polymorphic_allocator<char> > RecordData;
|
|
|
|
typedef std::deque< RecordData, std::pmr::polymorphic_allocator<RecordData> > Records;
|
|
typedef std::map< base::record_priority, Records, std::greater<base::record_priority>,
|
|
std::pmr::polymorphic_allocator< std::pair< const base::record_priority, Records > >
|
|
> Collection;
|
|
|
|
Collection records;
|
|
|
|
StorageManager & storage;
|
|
|
|
public:
|
|
MemoryLogHandler( StorageManager &, std::pmr::memory_resource *, std::size_t );
|
|
/* Ðàçìåñòü æóðíàëüíóþ çàïèñü â ïàìÿòè õðàíèëèùà. */
|
|
void publish( const LogRecord & );
|
|
/* Î÷èñòèòü ïàìÿòü õðàíèëèùà îò çàïèñåé.*/
|
|
void flush();
|
|
|
|
void process();
|
|
/* Óñòàíîâèòü âìåñòèòåëüíîñòü ñîîáùåíèé. */
|
|
void set_capacity( std::size_t );
|
|
void set_accumulation_policy( ACCUMULATION_POLICY );
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif /* LOGGING_MEMORYLOGHANDLER_H_ */
|