|
11 | 11 | #include "user_config.hpp" |
12 | 12 | #include "user_groups_config.hpp" |
13 | 13 |
|
14 | | -Napi::ThreadSafeFunction tsfn; |
| 14 | +/** |
| 15 | + * Note: After days of trying to get the libsession-util logger to play nice with console.log, |
| 16 | + * I've decided to just not log anything from libsession for now. |
| 17 | + * Note for my future self: |
| 18 | + * - we need a thread-safe function to be called in the add_logger callback here because if |
| 19 | + * the `env` is not valid it will crash the whole app without an error at all, |
| 20 | + * - macos crashes a lot more easily than linux, so better to debug this issue on macOS, |
| 21 | + * - using the thread-safe function below is working for linux, and kind of working for macOS, but |
| 22 | + * it also prevents the normal logging from being written to the inspector (macOS only) |
| 23 | + * |
| 24 | + * For all those reasons, and because we want a point release soon, there is no logging from |
| 25 | + * libsession-util for now. |
| 26 | + */ |
| 27 | +// Napi::ThreadSafeFunction tsfn; |
| 28 | +// tsfn = Napi::ThreadSafeFunction::New( |
| 29 | +// env, |
| 30 | +// Napi::Function::New(env, [](const Napi::CallbackInfo& info) {}), |
| 31 | +// "LoggerCallback", |
| 32 | +// 0, |
| 33 | +// 1); |
| 34 | + |
| 35 | +// session::add_logger([](std::string_view msg) { |
| 36 | +// tsfn.BlockingCall( |
| 37 | +// new std::string(msg), |
| 38 | +// [](Napi::Env env, Napi::Function jsCallback, std::string* msg) { |
| 39 | +// Napi::HandleScope scope(env); |
| 40 | +// Napi::Function consoleLog = env.Global() |
| 41 | +// .Get("console") |
| 42 | +// .As<Napi::Object>() |
| 43 | +// .Get("log") |
| 44 | +// .As<Napi::Function>(); |
| 45 | +// Napi::String jsStr = Napi::String::New(env, "libsession-util: " + *msg); |
| 46 | +// consoleLog.Call({jsStr}); |
| 47 | +// delete msg; |
| 48 | +// }); |
| 49 | +// }); |
| 50 | +// oxen::log::set_level_default(oxen::log::Level::info); |
15 | 51 |
|
16 | 52 | Napi::Object InitAll(Napi::Env env, Napi::Object exports) { |
17 | 53 | using namespace session::nodeapi; |
18 | 54 |
|
19 | | - tsfn = Napi::ThreadSafeFunction::New( |
20 | | - env, |
21 | | - Napi::Function::New(env, [](const Napi::CallbackInfo& info) {}), |
22 | | - "LoggerCallback", |
23 | | - 0, |
24 | | - 1); |
25 | | - |
26 | | - session::add_logger([](std::string_view msg) { |
27 | | - tsfn.BlockingCall( |
28 | | - new std::string(msg), |
29 | | - [](Napi::Env env, Napi::Function jsCallback, std::string* msg) { |
30 | | - Napi::HandleScope scope(env); |
31 | | - Napi::Function consoleLog = env.Global() |
32 | | - .Get("console") |
33 | | - .As<Napi::Object>() |
34 | | - .Get("log") |
35 | | - .As<Napi::Function>(); |
36 | | - Napi::String jsStr = Napi::String::New(env, "libsession-util: " + *msg); |
37 | | - consoleLog.Call({jsStr}); |
38 | | - delete msg; |
39 | | - }); |
40 | | - }); |
41 | | - oxen::log::set_level_default(oxen::log::Level::info); |
42 | | - |
43 | 55 | ConstantsWrapper::Init(env, exports); |
44 | 56 |
|
45 | 57 | // Group wrappers init |
|
0 commit comments