Skip to content

LogStreams

Maxime ROUFFET edited this page Mar 14, 2023 · 8 revisions

LogStreams are classes that can be created and registered into the logger for custom log output.
By default, a ALogStream has a levelFlags (see LogLevel) and a channelFilter (see LogChannel) to filter levels and channels.

// Create and register LogStream.
SA::ConsoleLogStream& cslStream  = SA::Debug::logger->CreateLogStream<SA::ConsoleLogStream>();

// Remove warning level.
cslStream.levelFlags &= ~SA::LogLevel::Warning;

// Add AssertionSuccess level.
cslStream.levelFlags |= SA::LogLevel::AssertionSuccess;

Custom implementation

Extend the log stream system by implementing your own stream class:

class MyCustomLogStream : ALogStream
{
public:
	int i = 0;
	float f = 0.0f;

	MyCustomLogStream(int _i, float _f);

	// Should implement.
	// Flushing stream.
	void Flush() override;

protected:
	// Must implement.
	// Custom output.
	void Output(const Log& _log) override;
};

// Create and register Stream.
MyCustomLogStream& myStream = SA::Debug::logger->CreateLogStream<MyCustomLogStream>(2, 12.45f);

// Edit stream parameters.
myStream.f = 5.2f;

See ConsoleLogStream.hpp/.cpp or FileLogStream.hpp/.cpp for exemple implementation.