Skip to content

Commit

Permalink
Add error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcrimsontianyu committed Feb 4, 2025
1 parent 4a95717 commit 0c45bfa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cpp/include/kvikio/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ void cufile_check_bytes_done_2(ssize_t nbytes_done, int line_number, char const*
}
}

#define KVIKIO_LOG_ERROR(err_msg) kvikio::detail::log_error(err_msg, __LINE__, __FILE__)
void log_error(std::string_view err_msg, int line_number, char const* filename);

} // namespace detail

} // namespace kvikio
15 changes: 15 additions & 0 deletions cpp/src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,19 @@
* limitations under the License.
*/

#include <iostream>

#include <kvikio/error.hpp>

namespace kvikio {

namespace detail {

void log_error(std::string_view err_msg, int line_number, char const* filename)
{
std::cerr << "KvikIO error at: " << filename << ":" << line_number << ": " << err_msg << "\n";
}

} // namespace detail

} // namespace kvikio
3 changes: 2 additions & 1 deletion cpp/src/file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <system_error>
#include <utility>

#include <kvikio/error.hpp>
#include <kvikio/file_utils.hpp>
#include <kvikio/shim/cufile.hpp>

Expand Down Expand Up @@ -57,7 +58,7 @@ bool FileWrapper::opened() const noexcept { return _fd != -1; }
void FileWrapper::close() noexcept
{
if (opened()) {
::close(_fd);
if (::close(_fd) != 0) { KVIKIO_LOG_ERROR("File cannot be closed"); }
_fd = -1;
}
}
Expand Down

0 comments on commit 0c45bfa

Please sign in to comment.