AuroraRuntime/Source/Logging/Sinks/RingBuffer.hpp

37 lines
1.2 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: RingBuffer.hpp
Date: 2022-1-24
Author: Reece
***/
#pragma once
namespace Aurora::Logging::Sinks
{
struct RingBufferSink : IBasicSinkRB
{
RingBufferSink(AuUInt32 count);
bool Init();
void OnMessageBlocking(AuUInt8 level, const ConsoleMessage &msg) override;
bool OnMessageNonblocking(AuUInt8 level, const ConsoleMessage &msg) override;
void OnFlush() override;
void SaveToPath(const AuString &path, bool binary = false) override;
AuList<ConsoleMessage> Export() override;
void PreviewRingBuffer(AuConsumer<AuPair<const AuList<ConsoleMessage> &, AuUInt32>> callback) override;
bool TryAddMsg(AuUInt8 level, const ConsoleMessage &msg, bool &drop);
private:
AuUInt32 maxCount_;
AuUInt32 index_;
AuList<ConsoleMessage> logBuffer_;
AuThreadPrimitives::Mutex logMutex_;
};
void NewRingBufferRelease(IBasicSink *logger);
IBasicSinkRB *NewRingBufferNew(AuUInt32 maxLogEntries);
}