mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 06:46:03 +00:00
remove the node sync logger
This commit is contained in:
parent
3dc968cfe2
commit
33b87e6582
@ -27,11 +27,6 @@
|
||||
"sources": [
|
||||
"src/node/node_init.cpp"
|
||||
]
|
||||
}],
|
||||
["realm_enable_sync", {
|
||||
"sources": [
|
||||
"src/node/node_sync_logger.cpp"
|
||||
]
|
||||
}]
|
||||
]
|
||||
},
|
||||
|
@ -30,10 +30,6 @@
|
||||
#include "realm/util/logger.hpp"
|
||||
#include "realm/util/uri.hpp"
|
||||
|
||||
#if REALM_PLATFORM_NODE
|
||||
#include "node/node_sync_logger.hpp"
|
||||
#endif
|
||||
|
||||
namespace realm {
|
||||
namespace js {
|
||||
|
||||
@ -59,10 +55,6 @@ public:
|
||||
static void set_sync_log_level(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
static void set_verify_servers_ssl_certificate(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
|
||||
#if REALM_PLATFORM_NODE
|
||||
static void set_sync_logger(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
#endif
|
||||
|
||||
// private
|
||||
static void refresh_access_token(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &);
|
||||
static void populate_sync_config(ContextType, ObjectType config_object, Realm::Config&);
|
||||
@ -73,10 +65,7 @@ public:
|
||||
MethodMap<T> const static_methods = {
|
||||
{"refreshAccessToken", wrap<refresh_access_token>},
|
||||
{"setLogLevel", wrap<set_sync_log_level>},
|
||||
{"setVerifyServersSslCertificate", wrap<set_verify_servers_ssl_certificate>},
|
||||
#if REALM_PLATFORM_NODE
|
||||
{"setSyncLogger", wrap<set_sync_logger>},
|
||||
#endif
|
||||
{"setVerifyServersSslCertificate", wrap<set_verify_servers_ssl_certificate>}
|
||||
};
|
||||
};
|
||||
|
||||
@ -153,16 +142,6 @@ void SyncClass<T>::set_verify_servers_ssl_certificate(ContextType ctx, ObjectTyp
|
||||
realm::SyncManager::shared().set_client_should_validate_ssl(verify_servers_ssl_certificate);
|
||||
}
|
||||
|
||||
#if REALM_PLATFORM_NODE
|
||||
template<typename T>
|
||||
void SyncClass<T>::set_sync_logger(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
validate_argument_count(argc, 1);
|
||||
auto callback = Value::validated_to_function(ctx, arguments[0]);
|
||||
node::SyncLoggerFactory *factory = new node::SyncLoggerFactory(ctx, this_object, callback); // Throws
|
||||
realm::SyncManager::shared().set_logger_factory(*factory);
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
void SyncClass<T>::refresh_access_token(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
|
||||
validate_argument_count(argc, 2);
|
||||
|
@ -1,94 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2016 Realm Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
#include <mutex>
|
||||
|
||||
#include "node_init.hpp"
|
||||
#include "node_class.hpp"
|
||||
#include "js_realm.hpp"
|
||||
#include "node_types.hpp"
|
||||
#include "node_sync_logger.hpp"
|
||||
|
||||
namespace realm {
|
||||
namespace node {
|
||||
|
||||
SyncLoggerQueue::~SyncLoggerQueue() noexcept
|
||||
{
|
||||
m_callback_this_object.Reset();
|
||||
m_callback.Reset();
|
||||
}
|
||||
|
||||
void SyncLoggerQueue::log_uv_callback()
|
||||
{
|
||||
// This function is always executed by the Node.js event loop
|
||||
// thread.
|
||||
Nan::HandleScope scope;
|
||||
v8::Local<v8::Object> this_object = Nan::New(m_callback_this_object);
|
||||
v8::Local<v8::Function> callback = Nan::New(m_callback);
|
||||
|
||||
std::queue<SyncLoggerMessage> popped;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex); // Throws
|
||||
popped.swap(m_log_queue);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (popped.empty())
|
||||
break;
|
||||
|
||||
Nan::TryCatch trycatch;
|
||||
v8::Local<v8::Value> argv[] = {
|
||||
Nan::New((int)(popped.front().m_level)),
|
||||
Nan::New(popped.front().m_message).ToLocalChecked()
|
||||
};
|
||||
Nan::MakeCallback(this_object, callback, 2, argv);
|
||||
if (trycatch.HasCaught()) {
|
||||
throw node::Exception(m_v8_isolate, trycatch.Exception());
|
||||
}
|
||||
popped.pop();
|
||||
}
|
||||
}
|
||||
|
||||
void SyncLogger::do_log(realm::util::Logger::Level level, std::string message)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex); // Throws
|
||||
m_log_queue.emplace(level, message);
|
||||
m_log_uv_async.send();
|
||||
}
|
||||
|
||||
SyncLoggerFactory::~SyncLoggerFactory() noexcept
|
||||
{
|
||||
m_callback_this_object.Reset();
|
||||
m_callback.Reset();
|
||||
}
|
||||
|
||||
std::unique_ptr<util::Logger> SyncLoggerFactory::make_logger(util::Logger::Level level)
|
||||
{
|
||||
v8::Local<v8::Object> this_object = Nan::New(m_callback_this_object);
|
||||
v8::Local<v8::Function> callback = Nan::New(m_callback);
|
||||
|
||||
SyncLogger *logger = new SyncLogger(m_v8_isolate, this_object, callback); // Throws
|
||||
logger->set_level_threshold(level);
|
||||
|
||||
return std::unique_ptr<util::Logger>(logger);
|
||||
}
|
||||
|
||||
} // namespace node
|
||||
} // namespace realm
|
@ -1,89 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2016 Realm Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef REALM_NODE_GLOBAL_LOGGER_HPP
|
||||
#define REALM_NODE_GLOBAL_LOGGER_HPP
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <queue>
|
||||
|
||||
#include <nan.h>
|
||||
|
||||
#include "node_uv_async.hpp"
|
||||
|
||||
namespace realm {
|
||||
namespace node {
|
||||
|
||||
struct SyncLoggerMessage {
|
||||
std::string m_message;
|
||||
realm::util::Logger::Level m_level;
|
||||
SyncLoggerMessage(realm::util::Logger::Level level, std::string message):
|
||||
m_message(message),
|
||||
m_level(level) { }
|
||||
};
|
||||
|
||||
class SyncLoggerQueue {
|
||||
public:
|
||||
SyncLoggerQueue(v8::Isolate* v8_isolate, v8::Local<v8::Object> callback_this_object, v8::Local<v8::Function> callback) :
|
||||
m_log_uv_async([this] { log_uv_callback(); }), // Throws
|
||||
m_v8_isolate(v8_isolate),
|
||||
m_callback_this_object(callback_this_object),
|
||||
m_callback(callback) { }
|
||||
~SyncLoggerQueue() noexcept;
|
||||
|
||||
protected:
|
||||
void log_uv_callback();
|
||||
std::queue<SyncLoggerMessage> m_log_queue;
|
||||
std::mutex m_mutex;
|
||||
UvAsync m_log_uv_async;
|
||||
|
||||
private:
|
||||
v8::Isolate* m_v8_isolate;
|
||||
Nan::Persistent<v8::Object> m_callback_this_object;
|
||||
Nan::Persistent<v8::Function> m_callback;
|
||||
};
|
||||
|
||||
class SyncLogger: public realm::util::RootLogger, public SyncLoggerQueue {
|
||||
public:
|
||||
SyncLogger(v8::Isolate* v8_isolate, v8::Local<v8::Object> callback_this_object, v8::Local<v8::Function> callback) :
|
||||
SyncLoggerQueue(v8_isolate, callback_this_object, callback) { }
|
||||
|
||||
protected:
|
||||
void do_log(realm::util::Logger::Level, std::string) override final;
|
||||
};
|
||||
|
||||
class SyncLoggerFactory : public realm::SyncLoggerFactory {
|
||||
public:
|
||||
SyncLoggerFactory(v8::Isolate* v8_isolate, v8::Local<v8::Object> callback_this_object, v8::Local<v8::Function> callback) :
|
||||
m_v8_isolate(v8_isolate),
|
||||
m_callback_this_object(callback_this_object),
|
||||
m_callback(callback) { }
|
||||
~SyncLoggerFactory() noexcept;
|
||||
|
||||
virtual std::unique_ptr<util::Logger> make_logger(util::Logger::Level level);
|
||||
private:
|
||||
v8::Isolate* m_v8_isolate;
|
||||
Nan::Persistent<v8::Object> m_callback_this_object;
|
||||
Nan::Persistent<v8::Function> m_callback;
|
||||
};
|
||||
|
||||
} // namespace node
|
||||
} // namespace realm
|
||||
|
||||
#endif // REALM_NODE_GLOBAL_LOGGER_HPP
|
Loading…
x
Reference in New Issue
Block a user