From 126e3e51e4eb03c1644b745935485557e41da5a6 Mon Sep 17 00:00:00 2001 From: Sri Ganesh Shiramshetty <115027993+GaneshVarma1@users.noreply.github.com> Date: Fri, 27 Jun 2025 09:31:52 -0500 Subject: [PATCH] feat: Enhance logging with detailed timestamps including milliseconds - Add milliseconds to timestamp format using %(msecs)03d - Include datefmt parameter for customizable timestamp format - Update default format to: %(asctime)s.%(msecs)03d - %(name)s - %(levelname)s - %(message)s - Update README documentation with enhanced logging example - Improve debugging and monitoring capabilities Fixes #728 - [FEATURE] Timestamp in log (basic feature) The enhanced logging now provides: - Millisecond precision for better debugging - Customizable date format - Backward compatibility with existing configs - Improved developer experience for troubleshooting --- README.md | 7 ++++--- preswald/utils.py | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f6646d5f8..4504d371f 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ Now run your app locally with: preswald run ``` -This command launches a development server, and Preswald will let you know where your app is hosted. Typically, itโ€™s here: +This command launches a development server, and Preswald will let you know where your app is hosted. Typically, it's here: ``` ๐ŸŒ App running at: http://localhost:8501 @@ -154,7 +154,8 @@ primaryColor = "#F89613" [logging] level = "INFO" # Options: DEBUG, INFO, WARNING, ERROR, CRITICAL -format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" +format = "%(asctime)s.%(msecs)03d - %(name)s - %(levelname)s - %(message)s" +datefmt = "%Y-%m-%d %H:%M:%S" # Optional: Customize timestamp format ``` ## **Use Cases** @@ -169,7 +170,7 @@ format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" ## **๐Ÿ“š Documentation** -Weโ€™re here to help! Check out our full documentation at [Preswald Docs](https://docs.preswald.com/). +We're here to help! Check out our full documentation at [Preswald Docs](https://docs.preswald.com/).
diff --git a/preswald/utils.py b/preswald/utils.py index 52da82fb0..740977cd2 100644 --- a/preswald/utils.py +++ b/preswald/utils.py @@ -63,10 +63,11 @@ def configure_logging(config_path: str | None = None, level: str | None = None): config_path: Path to preswald.toml file. If None, will look in current directory level: Directly specified logging level, overrides config file if provided """ - # Default configuration + # Default configuration with enhanced timestamp format log_config = { "level": "INFO", - "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s", + "format": "%(asctime)s.%(msecs)03d - %(name)s - %(levelname)s - %(message)s", + "datefmt": "%Y-%m-%d %H:%M:%S", } # Try to load from config file @@ -86,16 +87,17 @@ def configure_logging(config_path: str | None = None, level: str | None = None): if level is not None: log_config["level"] = level - # Configure logging + # Configure logging with enhanced timestamp format logging.basicConfig( level=getattr(logging, log_config["level"].upper()), format=log_config["format"], + datefmt=log_config.get("datefmt", "%Y-%m-%d %H:%M:%S"), force=True, # This resets any existing handlers ) # Create logger for this module logger = logging.getLogger(__name__) - logger.debug(f"Logging configured with level {log_config['level']}") + logger.debug(f"Logging configured with level {log_config['level']} and enhanced timestamp format") return log_config["level"]