Skip to content

Commit

Permalink
Merge pull request #50 from MAPF-Competition/develop
Browse files Browse the repository at this point in the history
Emergency fix on #48, program crash if a log file is not set.
  • Loading branch information
nobodyczcz authored Nov 21, 2023
2 parents ec853a4 + 5f97f8b commit cdd0356
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 40 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

Version 1.1.5 - 2023-11-21
----------------------------
Fixed:
- An emergency fix on program crash if a log file is not set with CLI.

Version 1.1.4 - 2023-11-18
----------------------------
Fixed:
Expand Down
15 changes: 6 additions & 9 deletions inc/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@ namespace keywords = boost::log::keywords;
class Logger
{
public:
Logger(){init();};
Logger(std::string filename, int severity=logging::trivial::info);
~Logger(){};

boost::shared_ptr<boost::log::v2_mt_posix::sinks::synchronous_sink<boost::log::v2_mt_posix::sinks::text_file_backend>> sink;

void set_logfile(std::string filename);
void init();

void log_info(std::string input);
void log_info(std::string input, int timestep);
void log_fatal(std::string input);
void log_fatal(std::string input, int timestep);
void log_warning(std::string input);
void log_warning(std::string input, int timestep);
void flush(){this->sink->flush();};
// void log_preprocessing(bool succ);
// void log_plan(bool succ,int time);
void flush();
private:
logging::core_ptr core;


};
43 changes: 17 additions & 26 deletions src/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,34 @@ namespace logging = boost::log;
namespace keywords = boost::log::keywords;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
using namespace logging::trivial;
src::severity_logger< severity_level > lg;


void Logger::set_logfile(std::string filename)
{
this->sink = logging::add_file_log
Logger::Logger(std::string filename, int severity){
this->core = logging::core::get();
logging::add_common_attributes();
logging::core::get()->set_filter
(
logging::trivial::severity >= severity
);

if (filename != "")
logging::add_file_log
(
keywords::file_name = filename,
keywords::format = "[%TimeStamp%]: *%Severity%* %Message%"
);
keywords::file_name = filename,
keywords::format = "[%TimeStamp%]: *%Severity%* %Message%"
);
}


void Logger::init()
{
// logging::add_file_log
// (
// keywords::format = "[%TimeStamp%]: %Message%"
// );
logging::core::get()->set_filter
(
logging::trivial::severity >= logging::trivial::info
);
void Logger::flush(){
this->core->flush();
}


void Logger::log_info(std::string input)
{
logging::add_common_attributes();

using namespace logging::trivial;
src::severity_logger< severity_level > lg;
BOOST_LOG_SEV(lg, info) << input;
}

Expand All @@ -53,20 +50,14 @@ void Logger::log_fatal(std::string input, int timestep)

void Logger::log_fatal(std::string input)
{
logging::add_common_attributes();

using namespace logging::trivial;
src::severity_logger< severity_level > lg;
BOOST_LOG_SEV(lg, fatal) << input;
}


void Logger::log_warning(std::string input)
{
logging::add_common_attributes();

using namespace logging::trivial;
src::severity_logger< severity_level > lg;
BOOST_LOG_SEV(lg, warning) << input;
}

Expand Down
6 changes: 2 additions & 4 deletions src/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main(int argc, char **argv)
("fileStoragePath", po::value<std::string>()->default_value(""), "the path to the storage path")
("planTimeLimit", po::value<int>()->default_value(INT_MAX), "the time limit for planner in seconds")
("preprocessTimeLimit", po::value<int>()->default_value(INT_MAX), "the time limit for preprocessing in seconds")
("logFile,l", po::value<std::string>(), "issue log file name");
("logFile,l", po::value<std::string>()->default_value(""), "issue log file name");
clock_t start_time = clock();
po::store(po::parse_command_line(argc, argv, desc), vm);

Expand All @@ -75,9 +75,7 @@ int main(int argc, char **argv)
base_folder += "/";
}

Logger *logger = new Logger();
if (vm.count("logFile"))
logger->set_logfile(vm["logFile"].as<std::string>());
Logger *logger = new Logger(vm["logFile"].as<std::string>());

MAPFPlanner *planner = nullptr;
// Planner is inited here, but will be managed and deleted by system_ptr deconstructor
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.4
1.1.5

0 comments on commit cdd0356

Please sign in to comment.