Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/internal-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ These flags and variables are for LWNode.js core development usage only. Do not

### Flags

#### `--dlog=<DLOG Tag>`

If the `--dlog` flag is specified on Tizen, LWNode prints logs via `DLOG` when
running from an embedder or the terminal. `DLOG_TAG` must be given, and is used
as the output TAG for loggers like `console.log()`.

```shell
--dlog=JS_APP
```

#### `--internal-log`

If the `--internal-log` flag is specified or the `LWNODE_INTERNAL_LOG` environment variable is set to 1, LWNode will print internal logs in release build.
Expand Down
23 changes: 23 additions & 0 deletions src/api/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,29 @@ void Engine::initialize() {
registerGCEventListeners();
}

#if defined(HOST_TIZEN)
if (EscargotShim::Global::flags()->isOn(
EscargotShim::Flag::Type::DlogOutput)) {
Flag* flag = EscargotShim::Global::flags()->getFlag(
EscargotShim::Flag::Type::DlogOutput);

std::string user_tag = flag->getValue();
if (!user_tag.empty()) {
LogKind::user()->tag = user_tag;
}

LogOption::setDefaultOutputInstantiator([]() {
static thread_local std::shared_ptr<Logger::Output> s_loggerOutput;
if (s_loggerOutput == nullptr) {
s_loggerOutput = std::static_pointer_cast<Logger::Output>(
std::make_shared<DlogOut>());
}
return s_loggerOutput;
});
LWNODE_DEV_LOG("DEV_LOG: OK");
}
#endif

mainThreadId_ = std::this_thread::get_id();
}

Expand Down
4 changes: 3 additions & 1 deletion src/api/utils/logger/flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void Flags::initFlags() {
addFlag<FlagWithNegativeValues>("--trace-call=", Flag::Type::TraceCall, true);
addFlag<Flag>("--internal-log", Flag::Type::InternalLog);
addFlag<Flag>("--start-debug-server", Flag::Type::DebugServer);
addFlag<FlagWithValues>("--dlog=", Flag::Type::DlogOutput, true);
}

bool Flag::isPrefixOf(const std::string& name) {
Expand Down Expand Up @@ -92,7 +93,8 @@ void Flags::add(const std::string& userOption) {
add(flag);

if (flag->type() == Flag::Type::TraceCall ||
flag->type() == Flag::Type::UnhandledRejections) {
flag->type() == Flag::Type::UnhandledRejections ||
flag->type() == Flag::Type::DlogOutput) {
std::string optionValues = userOption.substr(userOption.find_first_of('=') +
1); // +1 for skipping '='
auto tokens = strSplit(optionValues, ',');
Expand Down
14 changes: 12 additions & 2 deletions src/api/utils/logger/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Flag {
InternalLog,
LWNodeOther,
DebugServer,
DlogOutput,
};

Flag(const std::string& name, Type type, bool useAsPrefix = false)
Expand All @@ -61,6 +62,7 @@ class Flag {

virtual void addValue(const std::string& value){};
virtual bool hasValue(const std::string& value) { return false; }
virtual std::string getValue() { return ""; }

virtual void addNegativeValue(const std::string& value) {}
virtual bool hasNegativeValue(const std::string& value) { return false; }
Expand All @@ -85,6 +87,14 @@ class FlagWithValues : public Flag {
return values_.find(value) != values_.end();
}

virtual std::string getValue() override {
if (!values_.empty()) {
auto iter = values_.begin();
return *iter;
}
return "";
}

private:
std::set<std::string> values_;
};
Expand Down Expand Up @@ -131,13 +141,13 @@ class LWNODE_EXPORT Flags {
std::set<Flag*, FlagComparator> get() { return flags_; };
void set(std::set<Flag*, FlagComparator> flags) { flags_ = flags; }

Flag* getFlag(Flag::Type type);

private:
void initFlags();
Flag* findFlagObject(const std::string& name);
Flag* findFlagObject(Flag::Type type);

Flag* getFlag(Flag::Type type);

template <class T>
void addFlag(const char* name, Flag::Type type, bool useAsPrefix = false) {
validFlags_.push_back(std::make_unique<T>(name, type, useAsPrefix));
Expand Down