Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrouffet committed Mar 29, 2024
2 parents 8fd98f5 + f23b719 commit a570d4d
Show file tree
Hide file tree
Showing 15 changed files with 500 additions and 243 deletions.
4 changes: 4 additions & 0 deletions Include/SA/Logger/Log/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ namespace SA
/// Date time.
DateTime date;


/// Default constructor.
Log() = default;

/**
* \brief \e Value Move Constructor.
*
Expand Down
115 changes: 4 additions & 111 deletions Include/SA/Logger/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
#ifndef SAPPHIRE_LOGGER_LOGGER_GUARD
#define SAPPHIRE_LOGGER_LOGGER_GUARD

#include <list>

#include <SA/Logger/Streams/ALogStream.hpp>
#include <SA/Logger/Exceptions/Exception.hpp>
#include <SA/Logger/LoggerBase.hpp>

/**
* \file Logger.hpp
Expand All @@ -27,131 +24,27 @@ namespace SA
*
* Non-thread-safe logging.
*/
class Logger
class Logger : public LoggerBase
{
protected:
/// Registered output streams.
std::list<ALogStream*> mStreams;

/**
* \brief Current registered frame number.
* Use IncrementFrameNum() or SA_LOG_END_OF_FRAME() at the end of the frame to track frame number.
*/
uint32_t mFrameNum = 0u;

//{ Streams

/**
* \brief Process log to output.
*
* \param[in] _log Log to process.
* \param[in] _bForce Should force log process. Default is false.
*/
virtual void ProcessLog(const SA::Log& _log, bool _bForce = false);

/**
* \brief Register a stream to output.
*
* \param[in] _stream Stream to register.
*/
virtual void RegisterStream(ALogStream* _stream);

/**
* \brief Unregister a stream from output.
*
* \param[in] _stream Stream to unregister.
*
* \return true on success.
*/
virtual bool UnregisterStream(ALogStream* _stream);

//}

public:
/**
* \brief Destructor
* Destroy all created log streams.
*/
virtual ~Logger();

/**
* \brief Push a new log in logger.
*
* \param[in] _log Log to push.
*/
virtual void Log(SA::Log _log);

/**
* \brief Process exception.
*
* Log assertion on success, otherwise throw exception.
* Use SA_ASSERT as helper call.
*
* \tparam ExcepT Exception type.
* \param[in] _exc exception to process.
*/
template <typename ExcepT>
void Assert(ExcepT _exc);

//{ Streams

/**
* \brief Create a new stream to output in.
*
* \tparam StreamT Type of stream to create.
* \tparam Args... Argument variadic types to construct stream.
* \param[in] _args Arguments to construct stream.
*
* \return Newly created stream.
*/
template <typename StreamT, typename... Args>
StreamT& CreateSteam(Args&&... _args);

/**
* \brief Destroy a previously created stream.
*
* \tparam StreamT Type of stream to destroy.
* \param _stream Stream variable to destroy.
* \param _bFlush Should flush stream before destroy.
*
* \return true on destroy success.
*/
template <typename StreamT>
bool DestroyStream(StreamT& _stream, bool _bFlush = true);

/**
* Destroy all streams.
*
* \param _bFlush Should flush stream before destroy.
*/
void ClearStreams(bool _bFlush = true);

/**
* \brief Force logger to flush all streams.
*/
virtual void Flush();

//}

//{ Frame Num

/// Increment current registered frame number.
void IncrementFrameNum();
void IncrementFrameNum() override final;

/// Get current registered frame number.
uint32_t GetFrameNum() const;
uint32_t GetFrameNum() const override final;
//}
};

/// Global Debug namespace
namespace Debug
{
/// Logger instance.
extern Logger* logger;
}
}

#include <SA/Logger/Logger.inl>

/** \} */

Expand Down
147 changes: 147 additions & 0 deletions Include/SA/Logger/LoggerBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// Copyright (c) 2024 Sapphire's Suite. All Rights Reserved.

#pragma once

#ifndef SAPPHIRE_LOGGER_LOGGER_BASE_GUARD
#define SAPPHIRE_LOGGER_LOGGER_BASE_GUARD

#include <list>

#include <SA/Logger/Streams/ALogStream.hpp>
#include <SA/Logger/Exceptions/Exception.hpp>

/**
* \file LoggerBase.hpp
*
* \brief <b>Logger</b> base class implementation.
*
* \ingroup Logger
* \{
*/


namespace SA
{
/**
* \brief Logger base class implementation.
*/
class LoggerBase
{
protected:

//{ Streams

/// Registered output streams.
std::list<ALogStream*> mStreams;

/**
* \brief Process log to output.
*
* \param[in] _log Log to process.
* \param[in] _bForce Should force log process. Default is false.
*/
virtual void ProcessLog(const SA::Log& _log, bool _bForce = false);

/**
* \brief Register a stream to output.
*
* \param[in] _stream Stream to register.
*/
virtual void RegisterStream(ALogStream* _stream);

/**
* \brief Unregister a stream from output.
*
* \param[in] _stream Stream to unregister.
*
* \return true on success.
*/
virtual bool UnregisterStream(ALogStream* _stream);

//}

public:
/**
* \brief Destructor
* Destroy all created log streams.
*/
virtual ~LoggerBase();

/**
* \brief Push a new log in logger.
*
* \param[in] _log Log to push.
*/
virtual void Log(SA::Log _log);

/**
* \brief Process exception.
*
* Log assertion on success, otherwise throw exception.
* Use SA_ASSERT as helper call.
*
* \tparam ExcepT Exception type.
* \param[in] _exc exception to process.
*/
template <typename ExcepT>
void Assert(ExcepT _exc);


//{ Streams

/**
* \brief Create a new stream to output in.
*
* \tparam StreamT Type of stream to create.
* \tparam Args... Argument variadic types to construct stream.
* \param[in] _args Arguments to construct stream.
*
* \return Newly created stream.
*/
template <typename StreamT, typename... Args>
StreamT& CreateSteam(Args&&... _args);

/**
* \brief Destroy a previously created stream.
*
* \tparam StreamT Type of stream to destroy.
* \param _stream Stream variable to destroy.
* \param _bFlush Should flush stream before destroy.
*
* \return true on destroy success.
*/
template <typename StreamT>
bool DestroyStream(StreamT& _stream, bool _bFlush = true);

/**
* Destroy all streams.
*
* \param _bFlush Should flush stream before destroy.
*/
void ClearStreams(bool _bFlush = true);

/**
* \brief Force logger to flush all streams.
*/
virtual void Flush();

//}

//{ Frame Num

/// Increment current registered frame number.
virtual void IncrementFrameNum() = 0;

/// Get current registered frame number.
virtual uint32_t GetFrameNum() const = 0;

//}
};
}

#include <SA/Logger/LoggerBase.inl>


/** \} */

#endif // SAPPHIRE_LOGGER_LOGGER_BASE_GUARD
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) 2023 Sapphire's Suite. All Rights Reserved.
// Copyright (c) 2024 Sapphire's Suite. All Rights Reserved.

namespace SA
{
template <typename ExcepT>
void Logger::Assert(ExcepT _exc)
void LoggerBase::Assert(ExcepT _exc)
{
if(_exc.level == LogLevel::AssertFailure)
{
Expand All @@ -24,7 +24,7 @@ namespace SA
//{ Streams

template <typename StreamT, typename... Args>
StreamT& Logger::CreateSteam(Args&&... _args)
StreamT& LoggerBase::CreateSteam(Args&&... _args)
{
StreamT* const stream = new StreamT(std::forward<Args>(_args)...);

Expand All @@ -34,21 +34,21 @@ namespace SA
}

template <typename StreamT>
bool Logger::DestroyStream(StreamT& _stream, bool _bFlush)
bool LoggerBase::DestroyStream(StreamT& _stream, bool _bFlush)
{
StreamT* const streamPtr = &_stream;

const bool bUnregister = UnregisterSteam(streamPtr);
const bool bUnregisted = UnregisterSteam(streamPtr);

if (bUnregister)
if (bUnregisted)
{
if (_bFlush)
streamPtr->Flush();

delete streamPtr;
}

return bUnregister;
return bUnregisted;
}

//}
Expand Down
Loading

0 comments on commit a570d4d

Please sign in to comment.