Skip to content

Commit 30e35ab

Browse files
committed
chore: disable logging altogether because it prevents the inspector
to log anything on macos
1 parent 042ba38 commit 30e35ab

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"main": "index.js",
33
"name": "libsession_util_nodejs",
44
"description": "Wrappers for the Session Util Library",
5-
"version": "0.5.1",
5+
"version": "0.5.2",
66
"license": "GPL-3.0",
77
"author": {
88
"name": "Oxen Project",

src/addon.cpp

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,47 @@
1111
#include "user_config.hpp"
1212
#include "user_groups_config.hpp"
1313

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);
1551

1652
Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
1753
using namespace session::nodeapi;
1854

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-
4355
ConstantsWrapper::Init(env, exports);
4456

4557
// Group wrappers init

0 commit comments

Comments
 (0)