Skip to content

Commit

Permalink
log messages in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Sep 23, 2023
1 parent 8711bb3 commit 41d236c
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 29 deletions.
2 changes: 2 additions & 0 deletions source/Base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ add_library(alien_base_lib
Definitions.cpp
Definitions.h
Exceptions.h
FileLogger.cpp
FileLogger.h
GlobalSettings.cpp
GlobalSettings.h
Hashes.h
Expand Down
3 changes: 3 additions & 0 deletions source/Base/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ using std::int64_t;
using std::uint32_t;
using std::uint64_t;

class _FileLogger;
using FileLogger = std::shared_ptr<_FileLogger>;

constexpr float NEAR_ZERO = 1.0e-4f;

template <typename T>
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions source/Cli/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Base/LoggingService.h"
#include "Base/Resources.h"
#include "Base/StringHelper.h"
#include "Base/FileLogger.h"
#include "EngineImpl/SimulationControllerImpl.h"
#include "EngineInterface/Serializer.h"

Expand Down Expand Up @@ -91,6 +92,8 @@ namespace
int main(int argc, char** argv)
{
try {
FileLogger fileLogger = std::make_shared<_FileLogger>();

CLI::App app{"Command-line interface for ALIEN v" + Const::ProgramVersion};

//parse command line arguments
Expand Down
6 changes: 2 additions & 4 deletions source/Gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ PUBLIC
EditorModel.h
ExitDialog.cpp
ExitDialog.h
FileLogger.cpp
FileLogger.h
FpsController.cpp
FpsController.h
GenericFileDialogs.cpp
Expand All @@ -49,6 +47,8 @@ PUBLIC
GettingStartedWindow.h
GpuSettingsDialog.cpp
GpuSettingsDialog.h
GuiLogger.cpp
GuiLogger.h
HelpStrings.h
ImageToPatternDialog.cpp
ImageToPatternDialog.h
Expand Down Expand Up @@ -101,8 +101,6 @@ PUBLIC
Shader.h
ShaderWindow.cpp
ShaderWindow.h
SimpleLogger.cpp
SimpleLogger.h
SimulationParametersWindow.cpp
SimulationParametersWindow.h
SimulationScrollbar.cpp
Expand Down
7 changes: 2 additions & 5 deletions source/Gui/Definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@ using MassOperationsDialog = std::shared_ptr<_MassOperationsDialog>;
class _LogWindow;
using LogWindow = std::shared_ptr<_LogWindow>;

class _SimpleLogger;
using SimpleLogger = std::shared_ptr<_SimpleLogger>;

class _FileLogger;
using FileLogger = std::shared_ptr<_FileLogger>;
class _GuiLogger;
using GuiLogger = std::shared_ptr<_GuiLogger>;

class _UiController;
using UiController = std::shared_ptr<_UiController>;
Expand Down
10 changes: 5 additions & 5 deletions source/Gui/SimpleLogger.cpp → source/Gui/GuiLogger.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#include "SimpleLogger.h"
#include "GuiLogger.h"

#include "Base/LoggingService.h"

_SimpleLogger::_SimpleLogger()
_GuiLogger::_GuiLogger()
{
LoggingService::getInstance().registerCallBack(this);
}

_SimpleLogger::~_SimpleLogger()
_GuiLogger::~_GuiLogger()
{
LoggingService::getInstance().unregisterCallBack(this);
}

std::vector<std::string> const& _SimpleLogger::getMessages(Priority minPriority) const
std::vector<std::string> const& _GuiLogger::getMessages(Priority minPriority) const
{
if (Priority::Important == minPriority) {
return _importantLogMessages;
}
return _allLogMessages;
}

void _SimpleLogger::newLogMessage(Priority priority, std::string const& message)
void _GuiLogger::newLogMessage(Priority priority, std::string const& message)
{
_allLogMessages.emplace_back(message);
if (Priority::Important == priority) {
Expand Down
6 changes: 3 additions & 3 deletions source/Gui/SimpleLogger.h → source/Gui/GuiLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include "Base/LoggingService.h"
#include "Definitions.h"

class _SimpleLogger : public LoggingCallBack
class _GuiLogger : public LoggingCallBack
{
public:
_SimpleLogger();
virtual ~_SimpleLogger();
_GuiLogger();
virtual ~_GuiLogger();

std::vector<std::string> const& getMessages(Priority minPriority) const;

Expand Down
4 changes: 2 additions & 2 deletions source/Gui/LogWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include "Base/GlobalSettings.h"

#include "StyleRepository.h"
#include "SimpleLogger.h"
#include "GuiLogger.h"
#include "AlienImGui.h"

_LogWindow::_LogWindow(SimpleLogger const& logger)
_LogWindow::_LogWindow(GuiLogger const& logger)
: _AlienWindow("Log", "windows.log", false)
, _logger(logger)
{
Expand Down
4 changes: 2 additions & 2 deletions source/Gui/LogWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
class _LogWindow : public _AlienWindow
{
public:
_LogWindow(SimpleLogger const& logger);
_LogWindow(GuiLogger const& logger);
~_LogWindow();

private:
void processIntern();

bool _verbose = false;

SimpleLogger _logger;
GuiLogger _logger;
};
8 changes: 4 additions & 4 deletions source/Gui/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

#include "Base/GlobalSettings.h"
#include "Base/LoggingService.h"
#include "Base/Resources.h"
#include "Base/FileLogger.h"
#include "EngineInterface/Serializer.h"
#include "EngineImpl/SimulationControllerImpl.h"
#include "Base/Resources.h"

#include "MainWindow.h"
#include "SimpleLogger.h"
#include "FileLogger.h"
#include "GuiLogger.h"
#include "HelpStrings.h"

namespace
Expand All @@ -26,7 +26,7 @@ int main(int argc, char** argv)
auto inDebugMode = isInDebugMode(argc, argv);
GlobalSettings::getInstance().setDebugMode(inDebugMode);

SimpleLogger logger = std::make_shared<_SimpleLogger>();
GuiLogger logger = std::make_shared<_GuiLogger>();
FileLogger fileLogger = std::make_shared<_FileLogger>();

if (inDebugMode) {
Expand Down
4 changes: 2 additions & 2 deletions source/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "AboutDialog.h"
#include "MassOperationsDialog.h"
#include "LogWindow.h"
#include "SimpleLogger.h"
#include "GuiLogger.h"
#include "UiController.h"
#include "AutosaveController.h"
#include "GettingStartedWindow.h"
Expand Down Expand Up @@ -90,7 +90,7 @@ namespace
}
}

_MainWindow::_MainWindow(SimulationController const& simController, SimpleLogger const& logger)
_MainWindow::_MainWindow(SimulationController const& simController, GuiLogger const& logger)
{
_logger = logger;
_simController = simController;
Expand Down
4 changes: 2 additions & 2 deletions source/Gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class _MainWindow
{
public:
_MainWindow(SimulationController const& simController, SimpleLogger const& logger);
_MainWindow(SimulationController const& simController, GuiLogger const& logger);
void mainLoop();
void shutdown();

Expand Down Expand Up @@ -35,7 +35,7 @@ class _MainWindow
void reset();

GLFWwindow* _window;
SimpleLogger _logger;
GuiLogger _logger;

Viewport _viewport;

Expand Down

0 comments on commit 41d236c

Please sign in to comment.