mirror of
https://github.com/yawaflua/SpCloudCore.git
synced 2025-12-09 20:19:35 +02:00
introduce logger for publish contoller
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "../Service/AuthorizationService.cpp"
|
#include "../Service/AuthorizationService.cpp"
|
||||||
#include "../Service/FileProcessingService.cpp"
|
#include "../Service/FileProcessingService.cpp"
|
||||||
|
//#include "Service/Logger.cpp"
|
||||||
|
|
||||||
class PublishController
|
class PublishController
|
||||||
{
|
{
|
||||||
@@ -16,10 +17,14 @@ private:
|
|||||||
|
|
||||||
//std::string publish_app_path = "/mnt/c/Users/Danil/SpCloudApp";
|
//std::string publish_app_path = "/mnt/c/Users/Danil/SpCloudApp";
|
||||||
std::string publish_app_path = "/home/danilt2000/SpCloud/";
|
std::string publish_app_path = "/home/danilt2000/SpCloud/";
|
||||||
|
|
||||||
|
Logger& logger_;
|
||||||
|
|
||||||
//std::string publish_app_path = "C:/Temps/";// Todo delete if not needed
|
//std::string publish_app_path = "C:/Temps/";// Todo delete if not needed
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PublishController(httplib::Server& svr, AuthorizationService authorization, std::shared_ptr<FileProcessingService> file_processing) : authorization(authorization), file_processing(file_processing)
|
PublishController(httplib::Server& svr, AuthorizationService authorization, std::shared_ptr<FileProcessingService> file_processing, Logger& logger)
|
||||||
|
: authorization(authorization), file_processing(file_processing), logger_(logger)
|
||||||
{
|
{
|
||||||
/*this->authorization = authorization;
|
/*this->authorization = authorization;
|
||||||
|
|
||||||
@@ -27,6 +32,8 @@ public:
|
|||||||
|
|
||||||
svr.Post("/publish", [this](const httplib::Request& req, httplib::Response& res)
|
svr.Post("/publish", [this](const httplib::Request& req, httplib::Response& res)
|
||||||
{
|
{
|
||||||
|
logger_.log(INFO, "Start publish");
|
||||||
|
|
||||||
this->process_publish(req, res);
|
this->process_publish(req, res);
|
||||||
//httplib::Headers test = req.headers;//Todo add processing header for authorization layer
|
//httplib::Headers test = req.headers;//Todo add processing header for authorization layer
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,13 +22,17 @@ public:
|
|||||||
|
|
||||||
bool save_file(const std::string& filename, const std::string& content) {
|
bool save_file(const std::string& filename, const std::string& content) {
|
||||||
|
|
||||||
|
logger_.log(INFO, "Start saving file method");
|
||||||
|
|
||||||
//std::lock_guard<std::mutex> lock(file_mutex); // Блокируем мьютекс//Todo TEST STABILITY OF THIS
|
//std::lock_guard<std::mutex> lock(file_mutex); // Блокируем мьютекс//Todo TEST STABILITY OF THIS
|
||||||
|
|
||||||
std::ofstream ofs(filename, std::ios::binary);
|
std::ofstream ofs(filename, std::ios::binary);
|
||||||
|
|
||||||
|
logger_.log(INFO, "Create file stream");
|
||||||
|
|
||||||
if (!ofs) return false;
|
if (!ofs) return false;
|
||||||
|
|
||||||
logger_.log(INFO, "Start saving file");
|
logger_.log(INFO, "Start save content");
|
||||||
|
|
||||||
ofs << content;
|
ofs << content;
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ int main()
|
|||||||
|
|
||||||
auto file_processing = std::make_shared<FileProcessingService>(logger);
|
auto file_processing = std::make_shared<FileProcessingService>(logger);
|
||||||
|
|
||||||
PublishController publish_controller(svr, authorization_service, file_processing);
|
PublishController publish_controller(svr, authorization_service, file_processing, logger);
|
||||||
|
|
||||||
std::cout << "Server is running at http://localhost:8080" << '\n';
|
std::cout << "Server is running at http://localhost:8080" << '\n';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user