Skip to content

Commit

Permalink
Fix logging for open source project (facebookresearch#152)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebookresearch#152

The OSS logging macros only include definitions using the default log channel. This diff adds explicit log channel logging macros.

Differential Revision: D60429457
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Jul 30, 2024
1 parent 9eea57d commit 6e929e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions vrs/AsyncDiskFileChunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <unistd.h>
#endif

#include <atomic>
#include <condition_variable>
#include <deque>
#include <functional>
Expand Down
13 changes: 9 additions & 4 deletions vrs/oss/logging/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

#include <fmt/core.h>

#ifndef DEFAULT_LOG_CHANNEL
#error "DEFAULT_LOG_CHANNEL must be defined before including <logging/Log.h>"
#endif // DEFAULT_LOG_CHANNEL

namespace vrs {
namespace logging {

Expand Down Expand Up @@ -52,6 +48,7 @@ void log_every_n_seconds(
} // namespace logging
} // namespace vrs

#ifdef DEFAULT_LOG_CHANNEL
#define XR_LOG_DEFAULT(level, ...) log(level, DEFAULT_LOG_CHANNEL, fmt::format(__VA_ARGS__))
#define XR_LOG_EVERY_N_SEC_DEFAULT(level, nseconds, ...) \
log_every_n_seconds( \
Expand All @@ -70,3 +67,11 @@ void log_every_n_seconds(
XR_LOG_EVERY_N_SEC_DEFAULT(vrs::logging::Level::Warning, nseconds, __VA_ARGS__)
#define XR_LOGE_EVERY_N_SEC(nseconds, ...) \
XR_LOG_EVERY_N_SEC_DEFAULT(vrs::logging::Level::Error, nseconds, __VA_ARGS__)
#endif

#define XR_LOG_CHANNEL(level, channel, ...) log(level, channel, fmt::format(__VA_ARGS__))

#define XR_LOGCD(CHANNEL, ...) XR_LOG_CHANNEL(vrs::logging::Level::Debug, CHANNEL, __VA_ARGS__)
#define XR_LOGCI(CHANNEL, ...) XR_LOG_CHANNEL(vrs::logging::Level::Info, CHANNEL, __VA_ARGS__)
#define XR_LOGCW(CHANNEL, ...) XR_LOG_CHANNEL(vrs::logging::Level::Warning, CHANNEL, __VA_ARGS__)
#define XR_LOGCE(CHANNEL, ...) XR_LOG_CHANNEL(vrs::logging::Level::Error, CHANNEL, __VA_ARGS__)

0 comments on commit 6e929e9

Please sign in to comment.