Skip to content

Commit

Permalink
Added getLogger function and simple makefile in sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
dorosch committed Sep 23, 2022
1 parent f6cb5d7 commit 0845717
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 38 deletions.
17 changes: 0 additions & 17 deletions new_structure/radian/Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion new_structure/radian/include/radian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Radian {

class Application {
public:
std::unique_ptr<Tool::Logger> logger;
std::shared_ptr<Tool::Logger> logger;

Application();
virtual ~Application();
Expand Down
2 changes: 1 addition & 1 deletion new_structure/radian/include/radian.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Radian {

class Application {
public:
std::unique_ptr<Tool::Logger> logger;
std::shared_ptr<Tool::Logger> logger;

Application();
virtual ~Application();
Expand Down
19 changes: 19 additions & 0 deletions new_structure/radian/include/tools/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <map>
#include <memory>
#include <string>

#include <iostream>

#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
Expand Down Expand Up @@ -33,6 +36,22 @@ namespace Radian {
void error(const std::string &);
void critical(const std::string &);
};


static std::map<std::string, std::shared_ptr<Logger>> loggers;


inline std::shared_ptr<Logger> &getLogger(const std::string &name) {
auto logger = loggers.find(name);

if (logger == loggers.end()) {
loggers.emplace(name, std::make_shared<Logger>(name));

return loggers[name];
}

return logger->second;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion new_structure/radian/src/radian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using namespace Radian;


Application::Application() {
logger = std::make_unique<Tool::Logger>("app");
logger = Tool::getLogger("app");
}


Expand Down
28 changes: 10 additions & 18 deletions new_structure/sandbox/Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
TARGET = app
ENGINE = $(shell dirname $(shell pwd))/engine
TARGET = build/app

CXX = g++
INCLUDE = -I $(ENGINE)/include
LDFLAGS = -L $(ENGINE) -lradian
CXXFLAGS = -std=c++17 -Wall -Wextra -pedantic $(INCLUDE) $(LDFLAGS)
SOURCES = $(shell find ./ -name *.cpp)
OBJECTS = $(SOURCES:.cpp=.o)

all: $(TARGET)
.PHONY: $(TARGET)

run: $(TARGET)
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(ENGINE) ./$(TARGET)

$(TARGET): engine $(OBJECTS)
$(CXX) $(OBJECTS) $(CXXFLAGS) -o $(TARGET)
$(TARGET):
cmake -B build .
make -C build


engine:
$(MAKE) -C $(ENGINE)
run: $(TARGET)
./$(TARGET)

clean:
@rm -rf $(TARGET)
@rm -f $(OBJECTS)
@rm -rf ./build
@rm -f$(shell find ./src/ -name *.o)

0 comments on commit 0845717

Please sign in to comment.