Skip to content

feat: Enhance logging with detailed timestamps including milliseconds #766

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, its 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
Expand Down Expand Up @@ -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**
Expand All @@ -169,7 +170,7 @@ format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

## **📚 Documentation**

Were 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/).

<br>

Expand Down
10 changes: 6 additions & 4 deletions preswald/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]

Expand Down