-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add implementation for new ABI proxy_log_destination #336
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
|
||
#include <openssl/rand.h> | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
#include <utility> | ||
|
||
namespace proxy_wasm { | ||
|
@@ -916,6 +918,41 @@ Word log(Word level, Word address, Word size) { | |
return context->log(level, message.value()); | ||
} | ||
|
||
Word log_destination(Word destination, Word dest_size, Word level, Word address, Word size) { | ||
if (level > static_cast<uint64_t>(LogLevel::Max)) { | ||
return WasmResult::BadArgument; | ||
} | ||
auto *context = contextOrEffectiveContext(); | ||
const auto &log_destinations = context->wasm()->log_destinations(); | ||
|
||
auto message = context->wasmVm()->getMemory(address, size); | ||
if (!message) { | ||
return WasmResult::InvalidMemoryAccess; | ||
} | ||
auto dest = context->wasmVm()->getMemory(destination, dest_size); | ||
if (!dest) { | ||
return WasmResult::InvalidMemoryAccess; | ||
} | ||
context->log(level, dest.value()); | ||
// iterate over log_destinations map to check if dest | ||
// destination requested by plugin exists | ||
for (const auto &e : log_destinations) { | ||
if (e.first == dest.value()) { | ||
// write message to the file which is the value of the key if it exists | ||
std::ofstream log_file; | ||
log_file.open(e.second, std::ios::out | std::ios_base::app); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, this should be done on the proxy-side, so that it can use optimized logging facilities (if they exist), work with sandboxing, etc. Basically, this whole block could be replaced with:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated, thanks! |
||
if (!log_file) { | ||
return WasmResult::InvalidMemoryAccess; | ||
} | ||
log_file << message.value() << std::endl; | ||
log_file.close(); | ||
return WasmResult::Ok; | ||
} | ||
} | ||
// As a fallback, write to the default log destination. | ||
return context->log(level, message.value()); | ||
} | ||
|
||
Word get_log_level(Word result_level_uint32_ptr) { | ||
auto *context = contextOrEffectiveContext(); | ||
uint32_t level = context->getLogLevel(); | ||
|
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.
Debug leftover?
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.
yes. thanks for catching