Skip to content

Add config option for log level #2391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 23 additions & 0 deletions runtime/platform/log.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

def et_logging_enabled():
return native.read_config("executorch", "enable_et_log", "true") == "true"

def et_log_level():
raw_level = native.read_config("executorch", "log_level", "Info").lower()
if raw_level == "debug":
return "Debug"
elif raw_level == "info":
return "Info"
elif raw_level == "error":
return "Error"
elif raw_level == "fatal":
return "Fatal"
else:
fail("Unknown log level '{}'. Expected one of 'Debug', 'Info', 'Error', or 'Fatal'.".format(raw_level))

def get_et_logging_flags():
if et_logging_enabled():
# On by default.
return ["-DET_MIN_LOG_LEVEL=" + et_log_level()]
else:
return ["-DET_LOG_ENABLED=0"]
13 changes: 2 additions & 11 deletions runtime/platform/targets.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load(":log.bzl", "get_et_logging_flags")

def _select_pal(dict_):
"""Returns an element of `dict_` based on the value of the
Expand All @@ -10,16 +11,6 @@ def _select_pal(dict_):
fail("Missing key for executorch.pal_default value '{}' in dict '{}'".format(pal_default, dict_))
return dict_[pal_default]

def logging_enabled():
return native.read_config("executorch", "enable_et_log", "true") == "true"

def get_logging_flags():
if logging_enabled():
# On by default.
return []
else:
return ["-DET_LOG_ENABLED=0"]

def profiling_enabled():
return native.read_config("executorch", "prof_enabled", "false") == "true"

Expand Down Expand Up @@ -84,7 +75,7 @@ def define_common_targets():
"profiler.cpp",
"runtime.cpp",
],
exported_preprocessor_flags = get_profiling_flags() + get_logging_flags(),
exported_preprocessor_flags = get_profiling_flags() + get_et_logging_flags(),
exported_deps = [
"//executorch/runtime/platform:pal_interface",
":compiler",
Expand Down