Skip to content

Commit 131ce05

Browse files
GregoryComerfacebook-github-bot
authored andcommitted
Add config option for log level
Summary: Add a buck config option to set the ExecuTorch log level. Used as follows: `buck2 run ... -c executorch.log_level=[level]` Where [level] is one of Debug, Info, Error, or Fatal (case-in-sensitive). Log methods are refactored into a separate bazel file to facilitate re-use. I need to override the XNNPACK log level when ET log level is set to Debug, and I don't want to duplicate the log level parsing logic. Differential Revision: D54800053
1 parent 4670211 commit 131ce05

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

runtime/platform/log.bzl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
def et_logging_enabled():
3+
return native.read_config("executorch", "enable_et_log", "true") == "true"
4+
5+
def et_log_level():
6+
raw_level = native.read_config("executorch", "log_level", "Info").lower()
7+
if raw_level == "debug":
8+
return "Debug"
9+
elif raw_level == "info":
10+
return "Info"
11+
elif raw_level == "error":
12+
return "Error"
13+
elif raw_level == "fatal":
14+
return "Fatal"
15+
else:
16+
fail("Unknown log level '{}'. Expected one of 'Debug', 'Info', 'Error', or 'Fatal'.".format(raw_level))
17+
18+
def get_et_logging_flags():
19+
if et_logging_enabled():
20+
# On by default.
21+
return ["-DET_MIN_LOG_LEVEL=" + et_log_level()]
22+
else:
23+
return ["-DET_LOG_ENABLED=0"]

runtime/platform/targets.bzl

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
2+
load(":log.bzl", "get_et_logging_flags")
23

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

13-
def logging_enabled():
14-
return native.read_config("executorch", "enable_et_log", "true") == "true"
15-
16-
def get_logging_flags():
17-
if logging_enabled():
18-
# On by default.
19-
return []
20-
else:
21-
return ["-DET_LOG_ENABLED=0"]
22-
2314
def profiling_enabled():
2415
return native.read_config("executorch", "prof_enabled", "false") == "true"
2516

@@ -84,7 +75,7 @@ def define_common_targets():
8475
"profiler.cpp",
8576
"runtime.cpp",
8677
],
87-
exported_preprocessor_flags = get_profiling_flags() + get_logging_flags(),
78+
exported_preprocessor_flags = get_profiling_flags() + get_et_logging_flags(),
8879
exported_deps = [
8980
"//executorch/runtime/platform:pal_interface",
9081
":compiler",

0 commit comments

Comments
 (0)