Skip to content

Commit 45ebeb8

Browse files
committed
chore: improve logging format; set workflow output level to critical
Signed-off-by: Will Killian <[email protected]>
1 parent 462398f commit 45ebeb8

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

src/nat/cli/entrypoint.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@
5252
def setup_logging(log_level: str):
5353
"""Configure logging with the specified level"""
5454
numeric_level = LOG_LEVELS.get(log_level.upper(), logging.INFO)
55-
logging.basicConfig(level=numeric_level, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
55+
logging.basicConfig(
56+
level=numeric_level,
57+
format="%(asctime)s - %(levelname)-8s - %(name)s:%(lineno)d - %(message)s",
58+
datefmt="%Y-%m-%d %H:%M:%S",
59+
)
5660
return numeric_level
5761

5862

src/nat/front_ends/console/console_front_end_plugin.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,6 @@ async def run_single_query(query):
9595
else:
9696
assert False, "Should not reach here. Should have been caught by pre_run"
9797

98-
# Always log the result at INFO level
98+
# Always log the result at CRITICAL level so it is always visible
9999
result_message = f"\n{'-' * 50}\n{Fore.GREEN}Workflow Result:\n%s{Fore.RESET}\n{'-' * 50}"
100-
logger.info(result_message, runner_outputs)
101-
102-
# Additionally print to stdout if console handlers are set to a level higher than INFO
103-
# This ensures workflow results are always visible regardless of logging configuration
104-
root_logger = logging.getLogger()
105-
console_level_too_high = all(
106-
type(handler) is not logging.StreamHandler or handler.level > logging.INFO
107-
for handler in root_logger.handlers)
108-
109-
if console_level_too_high:
110-
print(f"\n{'-' * 50}\n{Fore.GREEN}Workflow Result:\n{runner_outputs}{Fore.RESET}\n{'-' * 50}")
100+
logger.critical(result_message, runner_outputs)

src/nat/observability/register.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ async def console_logging_method(config: ConsoleLoggingMethodConfig, builder: Bu
7777
level = getattr(logging, config.level.upper(), logging.INFO)
7878
handler = logging.StreamHandler(stream=sys.stdout)
7979
handler.setLevel(level)
80+
81+
# Set formatter to match the default CLI format
82+
formatter = logging.Formatter(
83+
fmt="%(asctime)s - %(levelname)-8s - %(name)s:%(lineno)d - %(message)s",
84+
datefmt="%Y-%m-%d %H:%M:%S",
85+
)
86+
handler.setFormatter(formatter)
87+
8088
yield handler
8189

8290

@@ -95,4 +103,12 @@ async def file_logging_method(config: FileLoggingMethod, builder: Builder):
95103
level = getattr(logging, config.level.upper(), logging.INFO)
96104
handler = logging.FileHandler(filename=config.path, mode="a", encoding="utf-8")
97105
handler.setLevel(level)
106+
107+
# Set formatter to match the default CLI format
108+
formatter = logging.Formatter(
109+
fmt="%(asctime)s - %(levelname)-8s - %(name)s:%(lineno)d - %(message)s",
110+
datefmt="%Y-%m-%d %H:%M:%S",
111+
)
112+
handler.setFormatter(formatter)
113+
98114
yield handler

0 commit comments

Comments
 (0)