Skip to content

Commit f9db679

Browse files
authored
Merge pull request #27 from Bilb/enable-logging-back
chore: enable logging back to console.log
2 parents 30e35ab + 6337d2e commit f9db679

File tree

3 files changed

+27
-39
lines changed

3 files changed

+27
-39
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
os: [windows-2022, macos-13, ubuntu-22.04]
22+
os: [windows-2022, macos-13, macos-14, ubuntu-22.04]
2323
env:
2424
SIGNAL_ENV: production
2525
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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.2",
5+
"version": "0.5.3",
66
"license": "GPL-3.0",
77
"author": {
88
"name": "Oxen Project",

src/addon.cpp

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

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);
14+
Napi::ThreadSafeFunction tsfn;
5115

5216
Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
5317
using namespace session::nodeapi;
5418

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+
5543
ConstantsWrapper::Init(env, exports);
5644

5745
// Group wrappers init

0 commit comments

Comments
 (0)