-
Notifications
You must be signed in to change notification settings - Fork 477
Add log level settings for auto skills #883
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,10 @@ def get_logger(log_file: Optional[str] = None, | |
| logger = logging.getLogger(logger_name) | ||
| logger.propagate = False | ||
| if logger_name in init_loggers: | ||
| # Update log level dynamically to respect current LOG_LEVEL env var | ||
| logger.setLevel(log_level) | ||
| for handler in logger.handlers: | ||
| handler.setLevel(log_level) | ||
| add_file_handler_if_needed(logger, log_file, file_mode, log_level) | ||
| return logger | ||
|
|
||
|
|
@@ -124,3 +128,28 @@ def add_file_handler_if_needed(logger, log_file, file_mode, log_level): | |
| file_handler.setFormatter(logger_format) | ||
| file_handler.setLevel(log_level) | ||
| logger.addHandler(file_handler) | ||
|
|
||
|
|
||
| def refresh_log_level(target_logger=None): | ||
| """ | ||
| Refresh logger level from LOG_LEVEL environment variable. | ||
|
|
||
| This is useful when LOG_LEVEL is changed after the logger was initialized. | ||
|
|
||
| Args: | ||
| target_logger: Logger to refresh. If None, uses the default logger. | ||
|
|
||
| Returns: | ||
| The new log level (as int). | ||
| """ | ||
| if target_logger is None: | ||
| target_logger = logger | ||
|
|
||
| log_level_str = os.getenv('LOG_LEVEL', 'INFO').upper() | ||
| log_level_int = getattr(logging, log_level_str, logging.INFO) | ||
|
|
||
| target_logger.setLevel(log_level_int) | ||
| for handler in target_logger.handlers: | ||
| handler.setLevel(log_level_int) | ||
|
Comment on lines
+151
to
+153
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic to set the level on the logger and its handlers is duplicated in the |
||
|
|
||
| return log_level_int | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid code duplication, you can use the new
refresh_log_levelfunction that you've added inms_agent/utils/logger.py. This will make the code more maintainable.You'll need to import it at the top of the file: