Skip to content

Commit

Permalink
Catch spdlog exception thrown when creating file
Browse files Browse the repository at this point in the history
Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey committed Sep 4, 2024
1 parent d6c602d commit 008078b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions log/src/Logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*
*/
#include <exception>
#include <iostream>
#include <memory>
#include <string>

Expand Down Expand Up @@ -85,11 +87,18 @@ void Logger::SetLogDestination(const std::string &_filename)

if (!_filename.empty())
{
this->dataPtr->fileSink =
std::make_shared<spdlog::sinks::basic_file_sink_mt>(_filename, true);
this->dataPtr->fileSink->set_formatter(this->dataPtr->formatter->clone());
this->dataPtr->fileSink->set_level(spdlog::level::trace);
this->dataPtr->sinks->add_sink(this->dataPtr->fileSink);
try
{
this->dataPtr->fileSink =
std::make_shared<spdlog::sinks::basic_file_sink_mt>(_filename, true);
this->dataPtr->fileSink->set_formatter(this->dataPtr->formatter->clone());
this->dataPtr->fileSink->set_level(spdlog::level::trace);
this->dataPtr->sinks->add_sink(this->dataPtr->fileSink);
}
catch(const std::exception &_e)
{
std::cerr << "Error creating log file: " << _e.what() << std::endl;
}
}
}

Expand Down

0 comments on commit 008078b

Please sign in to comment.