Skip to content

Commit 624ce59

Browse files
GregoryComerfacebook-github-bot
authored andcommitted
Add config option for log level (#2391)
Summary: Pull Request resolved: #2391 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. bypass-github-export-checks bypass-github-executorch-ci-checks Reviewed By: digantdesai Differential Revision: D54800053 fbshipit-source-id: f66e8524343d594c099cc864e6ad4d675ae19a3c
1 parent d42d21b commit 624ce59

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

runtime/platform/log.bzl

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