Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new macro(ENABLE_CUSTOM_LOGGER) to turn on Custom logger #345

Merged
merged 4 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion include/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
#include <iostream>
#include "windows_customizations.h"

#ifdef EXEC_ENV_OLS
#ifndef ENABLE_CUSTOM_LOGGER
#define ENABLE_CUSTOM_LOGGER
#endif // !ENABLE_CUSTOM_LOGGER
#endif // EXEC_ENV_OLS

namespace diskann
{
DISKANN_DLLEXPORT extern std::basic_ostream<char> cout;
Expand All @@ -18,7 +24,7 @@ enum class DISKANN_DLLEXPORT LogLevel
LL_Count
};

#ifdef EXEC_ENV_OLS
#ifdef ENABLE_CUSTOM_LOGGER
DISKANN_DLLEXPORT void SetCustomLogger(std::function<void(LogLevel, const char *)> logger);
#endif
} // namespace diskann
2 changes: 1 addition & 1 deletion include/logger_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ANNStreamBuf : public std::basic_streambuf<char>
// overflows/missing text are not a concern).
// This implies calling code _must_ either print std::endl or std::flush
// to ensure that the message is written immediately.
#ifdef EXEC_ENV_OLS
#ifdef ENABLE_CUSTOM_LOGGER
static const int BUFFER_SIZE = 1024;
#else
// Allocating an arbitrarily small buffer here because the overflow() and
Expand Down
7 changes: 4 additions & 3 deletions src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ DISKANN_DLLEXPORT ANNStreamBuf cerrBuff(stderr);
DISKANN_DLLEXPORT std::basic_ostream<char> cout(&coutBuff);
DISKANN_DLLEXPORT std::basic_ostream<char> cerr(&cerrBuff);

#ifdef EXEC_ENV_OLS
#ifdef ENABLE_CUSTOM_LOGGER
std::function<void(LogLevel, const char *)> g_logger;

void SetCustomLogger(std::function<void(LogLevel, const char *)> logger)
{
g_logger = logger;
cout << "Setted Custom Logger" << std::endl;
}
#endif

Expand All @@ -37,7 +38,7 @@ ANNStreamBuf::ANNStreamBuf(FILE *fp)
}
_fp = fp;
_logLevel = (_fp == stdout) ? LogLevel::LL_Info : LogLevel::LL_Error;
#ifdef EXEC_ENV_OLS
#ifdef ENABLE_CUSTOM_LOGGER
_buf = new char[BUFFER_SIZE + 1]; // See comment in the header
#else
_buf = new char[BUFFER_SIZE]; // See comment in the header
Expand Down Expand Up @@ -87,7 +88,7 @@ int ANNStreamBuf::flush()
}
void ANNStreamBuf::logImpl(char *str, int num)
{
#ifdef EXEC_ENV_OLS
#ifdef ENABLE_CUSTOM_LOGGER
str[num] = '\0'; // Safe. See the c'tor.
// Invoke the OLS custom logging function.
if (g_logger)
Expand Down