Skip to content

Commit abc6867

Browse files
committed
feat: log libsession-util lines to console.log
1 parent 632ddc3 commit abc6867

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/base_config.hpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace session::nodeapi {
1616
class ConfigBaseImpl;
1717
template <typename T>
1818
inline constexpr bool is_derived_napi_wrapper =
19-
std::is_base_of_v<ConfigBaseImpl, T>&& std::is_base_of_v<Napi::ObjectWrap<T>, T>;
19+
std::is_base_of_v<ConfigBaseImpl, T> && std::is_base_of_v<Napi::ObjectWrap<T>, T>;
2020

2121
/// Base implementation class for config types; this provides the napi wrappers for the base
2222
/// methods. Subclasses should inherit from this (alongside Napi::ObjectWrap<ConfigBaseWrapper>)
@@ -100,7 +100,24 @@ class ConfigBaseImpl {
100100
if (!second.IsEmpty() && !second.IsNull() && !second.IsUndefined())
101101
dump = toCppBufferView(second, class_name + ".new");
102102

103-
return std::make_shared<Config>(secretKey, dump);
103+
// return std::make_shared<Config>(secretKey, dump);
104+
std::shared_ptr<Config> config = std::make_shared<Config>(secretKey, dump);
105+
106+
Napi::Env env = info.Env();
107+
108+
config->logger = [env, class_name](session::config::LogLevel, std::string_view x) {
109+
std::string toLog =
110+
"libsession-util:" + std::string(class_name) + ": " + std::string(x) + "\n";
111+
112+
Napi::Function consoleLog = env.Global()
113+
.Get("console")
114+
.As<Napi::Object>()
115+
.Get("log")
116+
.As<Napi::Function>();
117+
consoleLog.Call({Napi::String::New(env, toLog)});
118+
};
119+
120+
return config;
104121
});
105122
}
106123

0 commit comments

Comments
 (0)