[+] IPCSink
This commit is contained in:
parent
85cace020a
commit
3985318566
@ -51,8 +51,10 @@ namespace Aurora::Logging
|
|||||||
*/
|
*/
|
||||||
AUKN_SHARED_API(NewDirectorySink, IBasicSink, const AuString &path, DirectoryLogger dirInfo, bool binary = false);
|
AUKN_SHARED_API(NewDirectorySink, IBasicSink, const AuString &path, DirectoryLogger dirInfo, bool binary = false);
|
||||||
|
|
||||||
// TODO:
|
/**
|
||||||
AUKN_SHARED_API(NewIPCSink, IBasicSink, const SocketConsole &console);
|
* @brief
|
||||||
|
*/
|
||||||
|
AUKN_SHARED_API(NewIPCSink, IBasicSink, const AuString &path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Constructs an in-memory ring buffer sink
|
* @brief Constructs an in-memory ring buffer sink
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "Sinks/StdConsole.hpp"
|
#include "Sinks/StdConsole.hpp"
|
||||||
#include "Sinks/RingBuffer.hpp"
|
#include "Sinks/RingBuffer.hpp"
|
||||||
#include "Sinks/DirLogArchive.hpp"
|
#include "Sinks/DirLogArchive.hpp"
|
||||||
|
#include "Sinks/IPCSink.hpp"
|
||||||
|
|
||||||
#if defined(AURORA_PLATFORM_WIN32)
|
#if defined(AURORA_PLATFORM_WIN32)
|
||||||
#include "Sinks/EventLog.Win32.hpp"
|
#include "Sinks/EventLog.Win32.hpp"
|
||||||
@ -94,14 +95,14 @@ namespace Aurora::Logging
|
|||||||
Sinks::NewFileSinkRelease(sink);
|
Sinks::NewFileSinkRelease(sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
AUKN_SYM IBasicSink *NewIPCSinkNew(const SocketConsole &console)
|
AUKN_SYM IBasicSink *NewIPCSinkNew(const AuString &path)
|
||||||
{
|
{
|
||||||
return {};
|
return Sinks::NewIPCSinkNew(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
AUKN_SYM void NewIPCSinkRelease(IBasicSink *logger)
|
AUKN_SYM void NewIPCSinkRelease(IBasicSink *sink)
|
||||||
{
|
{
|
||||||
|
Sinks::NewIPCSinkRelease(sink);
|
||||||
}
|
}
|
||||||
|
|
||||||
AUKN_SYM IBasicSinkRB *NewRingLoggerNew(AuUInt32 maxLogEntries)
|
AUKN_SYM IBasicSinkRB *NewRingLoggerNew(AuUInt32 maxLogEntries)
|
||||||
|
90
Source/Logging/Sinks/IPCSink.cpp
Normal file
90
Source/Logging/Sinks/IPCSink.cpp
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/***
|
||||||
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||||
|
|
||||||
|
File: IPCSink.cpp
|
||||||
|
Date: 2022-6-16
|
||||||
|
Author: Reece
|
||||||
|
***/
|
||||||
|
#include <Source/RuntimeInternal.hpp>
|
||||||
|
#include "IPCSink.hpp"
|
||||||
|
|
||||||
|
namespace Aurora::Logging::Sinks
|
||||||
|
{
|
||||||
|
IPCSink::IPCSink(const AuSPtr<Aurora::IO::IPC::IPCPipe> &pipe) : pipe_(pipe)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPCSink::Init()
|
||||||
|
{
|
||||||
|
this->logMutex_ = AuThreadPrimitives::MutexUnique();
|
||||||
|
return static_cast<bool>(this->pipe_) && static_cast<bool>(this->logMutex_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IPCSink::OnMessageBlocking(AuUInt8 level, const ConsoleMessage &msg)
|
||||||
|
{
|
||||||
|
AU_LOCK_GUARD(this->logMutex_);
|
||||||
|
|
||||||
|
auto str = msg.ToPersistentString();
|
||||||
|
auto startOffset = this->logBuffer_.GetWriteOffset();
|
||||||
|
|
||||||
|
|
||||||
|
msg.Write(this->logBuffer_);
|
||||||
|
|
||||||
|
|
||||||
|
if (!this->logBuffer_)
|
||||||
|
{
|
||||||
|
this->logBuffer_.writePtr = this->logBuffer_.base + startOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPCSink::OnMessageNonblocking(AuUInt8 level, const ConsoleMessage &msg)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IPCSink::OnFlush()
|
||||||
|
{
|
||||||
|
if (!this->logMutex_)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AU_LOCK_GUARD(this->logMutex_);
|
||||||
|
|
||||||
|
if (!this->logBuffer_.RemainingBytes())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->pipe_->Write(AuMemoryViewStreamRead(this->logBuffer_));
|
||||||
|
this->logBuffer_.ResetPositions();
|
||||||
|
}
|
||||||
|
|
||||||
|
IBasicSink *NewIPCSinkNew(const AuString &str)
|
||||||
|
{
|
||||||
|
auto pipe = AuIPC::ImportPipe(str);
|
||||||
|
if (!pipe)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto logger = _new IPCSink(pipe);
|
||||||
|
if (!logger)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!logger->Init())
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NewIPCSinkRelease(IBasicSink *logger)
|
||||||
|
{
|
||||||
|
AuSafeDelete<IPCSink *>(logger);
|
||||||
|
}
|
||||||
|
}
|
30
Source/Logging/Sinks/IPCSink.hpp
Normal file
30
Source/Logging/Sinks/IPCSink.hpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/***
|
||||||
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||||
|
|
||||||
|
File: IPCSink.hpp
|
||||||
|
Date: 2022-6-16
|
||||||
|
Author: Reece
|
||||||
|
***/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Aurora::Logging::Sinks
|
||||||
|
{
|
||||||
|
struct IPCSink : IBasicSink
|
||||||
|
{
|
||||||
|
IPCSink(const AuSPtr<Aurora::IO::IPC::IPCPipe> &pipe);
|
||||||
|
|
||||||
|
bool Init();
|
||||||
|
|
||||||
|
void OnMessageBlocking(AuUInt8 level, const ConsoleMessage &msg) override;
|
||||||
|
bool OnMessageNonblocking(AuUInt8 level, const ConsoleMessage &msg) override;
|
||||||
|
void OnFlush() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
AuSPtr<Aurora::IO::IPC::IPCPipe> pipe_;
|
||||||
|
AuByteBuffer logBuffer_;
|
||||||
|
AuThreadPrimitives::MutexUnique_t logMutex_;
|
||||||
|
};
|
||||||
|
|
||||||
|
void NewIPCSinkRelease(IBasicSink *logger);
|
||||||
|
IBasicSink *NewIPCSinkNew(const AuString &str);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user