Skip to content

Conversation

@popenta
Copy link
Collaborator

@popenta popenta commented Jun 13, 2025

An user can set the log_level config entry using mxpy config set log_level error. The allowed values are [debug, info, warning, error]. The default value is info.

Additionally, the --log-level argument can be provided with any mxpy command. Explicitly specifying this argument will override the value set in the config.

@popenta popenta self-assigned this Jun 13, 2025
@popenta popenta marked this pull request as draft June 13, 2025 07:16
Base automatically changed from remove-deprecated-recall-nonce-arg to feat/next June 18, 2025 13:52
@popenta popenta marked this pull request as ready for review June 18, 2025 13:53
andreibancioiu
andreibancioiu previously approved these changes Jun 18, 2025
args.insert(0, verbose_arg)


def _handle_log_level_argument(args: list[str]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have handled both --verbose and --log-level in a single function of the kind e.g. _handle_global_arguments or _handle_universal_arguments. Just an opinion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, moved the logic in _handle_global_arguments().

parser.add_argument(
"--log-level",
type=str,
default=config.get_log_level_from_config(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


def get_log_level_from_config():
log_level = get_value("log_level")
if log_level not in ["debug", "info", "warning", "error"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List could have been in constants.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


class LogLevelError(KnownError):
def __init__(self, log_level: str):
super().__init__(f"Log level not accepted: {log_level}. Choose between ['debug', 'info', 'warning', 'error'].")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List could have been in constants.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@andreibancioiu andreibancioiu requested a review from Copilot June 18, 2025 16:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds functionality to configure the logging level via the configuration file or through the --log-level CLI argument. Key changes include:

  • Introducing a new LogLevelError in errors.py.
  • Adding a get_log_level_from_config function to ensure the log level is valid in config.py.
  • Updating cli.py to parse and reorder the --log-level argument, and applying the log level during logging initialization.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
multiversx_sdk_cli/errors.py Adds LogLevelError to error handling with a clear message for invalid log levels.
multiversx_sdk_cli/config.py Sets a default log_level and adds a helper to fetch and validate its value.
multiversx_sdk_cli/cli.py Adds support for the --log-level CLI argument and reorders arguments accordingly.

log_level_arg = "--log-level"

if log_level_arg in args:
index = args.index(log_level_arg)
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a safety check to ensure that a value follows '--log-level' in the args list to prevent potential index errors if the argument is provided without an accompanying value.

Suggested change
index = args.index(log_level_arg)
index = args.index(log_level_arg)
if index + 1 >= len(args) or args[index + 1].startswith("--"):
raise ValueError(f"Argument '{log_level_arg}' must be followed by a log level value.")

Copilot uses AI. Check for mistakes.
andreibancioiu
andreibancioiu previously approved these changes Jun 19, 2025
if log_level not in LOG_LEVELS:
default_log_level = get_defaults()["log_level"]
show_warning(f"Invalid log level set in config: [{log_level}]. Defaulting to [{default_log_level}].")
return default_log_level
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mypy warning.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@popenta popenta merged commit 7c06fe8 into feat/next Jun 19, 2025
13 of 14 checks passed
@popenta popenta deleted the set-log-level branch June 19, 2025 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants