Skip to content

Commit

Permalink
OrcLib: Log: FileSink: add method 'OutputPath' to return absolute fil…
Browse files Browse the repository at this point in the history
…e path
  • Loading branch information
fabienfl-orc committed Feb 9, 2021
1 parent e0f52a1 commit 8ca11b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/OrcCommand/UtilitiesLogger.h
Expand Up @@ -45,6 +45,7 @@ class UtilitiesLogger
void Open(const std::filesystem::path& path, std::error_code& ec) { m_fileSink->Open(path, ec); }
bool IsOpen() const { return m_fileSink->IsOpen(); }
void Close() { return m_fileSink->Close(); }
std::optional<std::filesystem::path> OutputPath() const { return m_fileSink->OutputPath(); }

private:
FileSinkT* m_fileSink;
Expand Down
22 changes: 21 additions & 1 deletion src/OrcLib/Log/Sink/FileSink.h
Expand Up @@ -12,6 +12,7 @@
#include <cassert>
#include <fstream>
#include <iostream>
#include <filesystem>

#include <spdlog/sinks/base_sink.h>
#include <spdlog/sinks/basic_file_sink.h>
Expand Down Expand Up @@ -81,7 +82,16 @@ class FileSink : public spdlog::sinks::base_sink<Mutex>
m_memorySink.reset();
}

m_fileSink = std::make_unique<SpdlogFileSink>(path.string());
// use absolute path so spdlog's functions like Filename_t() will also return the same absolute path
auto absolutePath = std::filesystem::absolute(path, ec);
if (ec)
{
Log::Warn(L"Failed to resolve absolute path: {} [{}]", path, ec);
absolutePath = path; // better than empty
ec.clear();
}

m_fileSink = std::make_unique<SpdlogFileSink>(absolutePath.string());

// Current sink_it_ will handle filtering
m_fileSink->set_level(spdlog::level::trace);
Expand All @@ -105,6 +115,16 @@ class FileSink : public spdlog::sinks::base_sink<Mutex>
m_fileSink.reset();
}

std::optional<std::filesystem::path> OutputPath() const
{
if (m_fileSink)
{
return m_fileSink->filename();
}

return {};
}

protected:
void set_pattern_(const std::string& pattern) override
{
Expand Down

0 comments on commit 8ca11b5

Please sign in to comment.