-
Notifications
You must be signed in to change notification settings - Fork 5
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
Standalone 3/N: Define the Zarr logger #295
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c7832d7
Move driver source files and tests to a separate directory.
aliddell a811e22
Define the Zarr streaming API.
aliddell cf89e13
Define the Zarr logger.
aliddell fff86c6
Rename zarr.h to acquire.zarr.h.
aliddell 61a53bc
Merge branch 'standalone-sequence-3' into standalone-sequence-4
aliddell bdd0c51
Instantiate the logger's mutex.
aliddell d099795
Document the StreamSettings getters.
aliddell cfd412e
Merge remote-tracking branch 'upstream/standalone-sequence-3' into st…
aliddell da98e57
call it 'type'
aliddell aa3489e
Merge branch 'standalone-sequence-3' into standalone-sequence-4
aliddell 996d22e
Document that ZarrStream_append will block for compression and flushing
aliddell d6ea43e
Merge branch 'standalone-sequence-3' into standalone-sequence-4
aliddell e546f7d
Respond to PR comments.
aliddell 2d6aae1
Merge branch 'standalone-sequence-2' into standalone-sequence-3
aliddell a1b0034
Merge remote-tracking branch 'upstream/main' into standalone-sequence-3
aliddell cb5414f
Merge remote-tracking branch 'upstream/main' into standalone-sequence-4
aliddell 42a4940
Respond to PR comments.
aliddell 9a6212f
Merge branch 'standalone-sequence-3' into standalone-sequence-4
aliddell ca93466
Merge remote-tracking branch 'upstream/main' into standalone-sequence-4
aliddell bda14d7
Respond to PR comments
aliddell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
add_subdirectory(logger) | ||
if (BUILD_ACQUIRE_DRIVER_ZARR) | ||
add_subdirectory(driver) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
add_library(acquire-logger | ||
logger.hh | ||
logger.cpp | ||
) | ||
|
||
target_include_directories(acquire-logger | ||
PRIVATE | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> | ||
) | ||
|
||
set_target_properties(acquire-logger PROPERTIES | ||
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" | ||
) | ||
|
||
install(TARGETS acquire-logger | ||
LIBRARY DESTINATION lib | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "logger.hh" | ||
|
||
#include <iomanip> | ||
#include <string> | ||
#include <thread> | ||
|
||
LogLevel Logger::current_level_ = LogLevel_Info; | ||
std::mutex Logger::log_mutex_{}; | ||
|
||
void | ||
Logger::set_log_level(LogLevel level) | ||
{ | ||
current_level_ = level; | ||
} | ||
|
||
LogLevel | ||
Logger::get_log_level() | ||
{ | ||
return current_level_; | ||
} | ||
|
||
std::string | ||
Logger::get_timestamp_() | ||
{ | ||
|
||
auto now = std::chrono::system_clock::now(); | ||
auto time = std::chrono::system_clock::to_time_t(now); | ||
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>( | ||
now.time_since_epoch()) % | ||
1000; | ||
|
||
std::tm tm{}; | ||
#if defined(_WIN32) | ||
localtime_s(&tm, &time); | ||
#else | ||
localtime_r(&time, &tm); | ||
#endif | ||
|
||
std::ostringstream ss; | ||
ss << std::put_time(&tm, "%Y-%m-%d %H:%M:%S") << '.' << std::setfill('0') | ||
<< std::setw(3) << ms.count(); | ||
|
||
return ss.str(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "logger.types.h" | ||
|
||
#include <filesystem> | ||
#include <iostream> | ||
#include <mutex> | ||
#include <sstream> | ||
|
||
class Logger | ||
{ | ||
public: | ||
static void set_log_level(LogLevel level); | ||
static LogLevel get_log_level(); | ||
|
||
template<typename... Args> | ||
static std::string log(LogLevel level, | ||
const char* file, | ||
int line, | ||
const char* func, | ||
Args&&... args) | ||
{ | ||
namespace fs = std::filesystem; | ||
|
||
std::scoped_lock lock(log_mutex_); | ||
|
||
std::string prefix; | ||
auto stream = &std::cout; | ||
|
||
switch (level) { | ||
case LogLevel_Debug: | ||
prefix = "[DEBUG] "; | ||
break; | ||
case LogLevel_Info: | ||
prefix = "[INFO] "; | ||
break; | ||
case LogLevel_Warning: | ||
prefix = "[WARNING] "; | ||
break; | ||
default: | ||
prefix = "[ERROR] "; | ||
stream = &std::cerr; | ||
break; | ||
} | ||
|
||
fs::path filepath(file); | ||
std::string filename = filepath.filename().string(); | ||
|
||
std::ostringstream ss; | ||
ss << get_timestamp_() << " " << prefix << filename << ":" << line | ||
<< " " << func << ": "; | ||
|
||
format_arg_(ss, std::forward<Args>(args)...); | ||
|
||
std::string message = ss.str(); | ||
*stream << message << std::endl; | ||
|
||
return message; | ||
} | ||
|
||
private: | ||
static LogLevel current_level_; | ||
static std::mutex log_mutex_; | ||
|
||
static void format_arg_(std::ostream& ss) {}; // base case | ||
template<typename T, typename... Args> | ||
static void format_arg_(std::ostream& ss, T&& arg, Args&&... args) { | ||
ss << std::forward<T>(arg); | ||
format_arg_(ss, std::forward<Args>(args)...); | ||
} | ||
|
||
static std::string get_timestamp_(); | ||
}; | ||
|
||
#define LOG_DEBUG(...) \ | ||
Logger::log(LogLevel_Debug, __FILE__, __LINE__, __func__, __VA_ARGS__) | ||
#define LOG_INFO(...) \ | ||
Logger::log(LogLevel_Info, __FILE__, __LINE__, __func__, __VA_ARGS__) | ||
#define LOG_WARNING(...) \ | ||
Logger::log(LogLevel_Warning, __FILE__, __LINE__, __func__, __VA_ARGS__) | ||
#define LOG_ERROR(...) \ | ||
Logger::log(LogLevel_Error, __FILE__, __LINE__, __func__, __VA_ARGS__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
typedef enum { | ||
LogLevel_Debug, | ||
LogLevel_Info, | ||
LogLevel_Warning, | ||
LogLevel_Error | ||
} LogLevel; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I mentioned this in the large PR review. I would extract this code and
std::put_time
to a separate function. This snippet is copied from a logger that I wrote a while back so it may need to be adjusted a bit if you decide to use it.