Skip to content
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

Rationalize output to stdout for automated testing #57

Open
jimthompson5802 opened this issue Dec 9, 2024 · 1 comment
Open

Rationalize output to stdout for automated testing #57

jimthompson5802 opened this issue Dec 9, 2024 · 1 comment

Comments

@jimthompson5802
Copy link
Owner

Automted testing running multiple puzzles generates verbose messages to stdout. Determine if we can reduce the volume. Example of verbose output for a 10 puzzle test.
sample_automated_run_log.txt

@jimthompson5802
Copy link
Owner Author

Couple of possible implementations.

Github Copilot

import logging

# Define a new logging level
CUSTOM_LOG_LEVEL = 25  # Choose a number between existing levels (e.g., between WARNING (30) and INFO (20))
logging.addLevelName(CUSTOM_LOG_LEVEL, "CUSTOM")

# Define a custom logging method
def custom(self, message, *args, **kwargs):
    if self.isEnabledFor(CUSTOM_LOG_LEVEL):
        self._log(CUSTOM_LOG_LEVEL, message, args, **kwargs)

# Add the custom method to the Logger class
logging.Logger.custom = custom

# Example usage
logger = logging.getLogger(__name__)
logger.setLevel(CUSTOM_LOG_LEVEL)

# Create a console handler and set the level to custom
ch = logging.StreamHandler()
ch.setLevel(CUSTOM_LOG_LEVEL)

# Create a formatter and set it for the handler
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)

# Add the handler to the logger
logger.addHandler(ch)

# Log a message with the custom level
logger.custom("This is a custom log message.")

perplexity.ai

import logging

# Define and register the custom level
VERBOSE = 15
logging.addLevelName(VERBOSE, "VERBOSE")

# Add a custom logging method
def verbose(self, message, *args, **kwargs):
    if self.isEnabledFor(VERBOSE):
        self._log(VERBOSE, message, args, **kwargs)

# Add the method to the Logger class
logging.Logger.verbose = verbose

# Use the new level
logger = logging.getLogger(__name__)
logger.verbose("This is a verbose message")

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

No branches or pull requests

1 participant