Troubleshooting Guide¶
This guide covers common issues you may encounter when using Logly and provides solutions to resolve them.
Quick Diagnosis¶
Use this checklist to quickly identify the type of issue you're experiencing:
- Installation Issues: Can't install or import Logly → Installation Problems
- File Access Errors: Logs not writing to files → File Access Issues
- Permission Denied: Access denied errors → Permission Issues
- Network Errors: Version check failures → Network Issues
- Configuration Errors: Invalid settings → Configuration Problems
- Performance Issues: Slow logging or high memory → Performance Problems
- Import Errors: Can't import Logly → Import and Compatibility Issues
- Rotation Not Working: Files not rotating → File Rotation Issues
- Missing Logs: Logs disappearing → Missing or Lost Logs
- Callback Errors: Callback failures → Callback Issues
Installation Problems¶
Issue: pip install logly
fails¶
Symptoms:
ERROR: Could not find a version that satisfies the requirement logly
ERROR: Failed building wheel for logly
Solutions:
-
Upgrade pip, setuptools, and wheel:
-
Check Python version (requires Python 3.10+):
If below 3.10, upgrade Python or use a virtual environment with Python 3.10+. -
Install from PyPI with verbose output:
-
Try installing with no cache:
-
Install specific version:
Issue: Import error after installation¶
Symptoms:
Solutions:
-
Verify installation:
-
Check you're using the correct Python/pip:
-
Verify virtual environment is activated:
-
Reinstall Logly:
File Access Issues¶
Issue: Logs not writing to file¶
Symptoms: - No log file created - Log file is empty - File exists but logs are missing
Solutions:
-
Verify sink is added:
-
Check directory exists:
-
Use absolute paths to avoid ambiguity:
-
Verify
logger.complete()
is called: -
Check async writing isn't buffering:
Issue: File locked or in use¶
Symptoms:
IOError: [Errno 13] Permission denied: 'app.log'
PermissionError: [WinError 32] The process cannot access the file
Solutions:
-
Remove all handlers before rotation:
-
Check if file is open in another program:
- Close text editors, log viewers, or other programs using the file
-
On Windows, check Task Manager for processes locking the file
-
Use different log file:
-
Enable date-based naming to avoid conflicts:
Permission Issues¶
Issue: Permission denied writing logs¶
Symptoms:
PermissionError: [Errno 13] Permission denied: '/var/log/app.log'
IOError: [Errno 13] Permission denied
Solutions:
-
Use writable directory:
-
Check directory permissions (Linux/Mac):
-
Run with appropriate permissions:
-
Use current working directory:
Issue: Cannot create directory¶
Symptoms:
PermissionError: [Errno 13] Permission denied: 'logs'
FileNotFoundError: [Errno 2] No such file or directory
Solutions:
-
Create directory with proper error handling:
-
Use environment-appropriate paths:
Network Issues¶
Issue: Version check failing¶
Symptoms:
Solutions:
-
Disable version checking if behind firewall:
-
Configure proxy settings (if needed):
-
Check network connectivity:
-
Version check is async and non-blocking:
- The version check runs in background and won't affect logging
- If it fails, logging continues normally
- Safe to ignore if not critical
Configuration Problems¶
Issue: Invalid log level error¶
Symptoms:
ValueError: Invalid log level: 'INVALID_LEVEL'.
Valid levels are: TRACE, DEBUG, INFO, SUCCESS, WARNING, ERROR, CRITICAL
Solutions:
-
Use valid log levels:
-
Valid levels are:
TRACE
- Most verboseDEBUG
- Development debuggingINFO
- General informationSUCCESS
- Successful operationsWARNING
- Warning messagesERROR
- Error conditionsCRITICAL
- Critical failures
Issue: Invalid rotation policy¶
Symptoms:
ValueError: Invalid rotation policy: 'weekly'.
Valid policies are: daily, hourly, minutely, or size-based (e.g., '10MB')
Solutions:
-
Use valid rotation policies:
# Time-based rotation logger.add("app.log", rotation="daily") # ✓ logger.add("app.log", rotation="hourly") # ✓ logger.add("app.log", rotation="minutely") # ✓ # Size-based rotation logger.add("app.log", rotation="10MB") # ✓ logger.add("app.log", rotation="1GB") # ✓ # Invalid logger.add("app.log", rotation="weekly") # ✗ Not supported
-
Size format examples:
Issue: Invalid format string¶
Symptoms:
Solutions:
-
Use valid format placeholders:
# Valid placeholders logger.add("app.log", format="{time} [{level}] {message}") logger.add("app.log", format="{time} | {level:8} | {module}:{function} | {message}") # Available placeholders: # {time} - Timestamp # {level} - Log level # {message} - Log message # {module} - Module name # {function} - Function name # {extra} - Extra fields
-
Check for syntax errors:
Performance Problems¶
Issue: Logging is slow¶
Symptoms: - Application hangs during logging - High latency when logging - Logs take seconds to write
Solutions:
-
Enable async writing (default):
-
Increase buffer size for high-throughput:
-
Reduce flush frequency:
-
Disable features you don't need:
-
Use storage_levels to filter:
Issue: High memory usage¶
Symptoms: - Memory usage grows over time - Out of memory errors - Process using too much RAM
Solutions:
-
Reduce buffer sizes:
-
Flush more frequently:
-
Enable rotation to limit file size:
-
Remove unnecessary sinks:
-
Disable callbacks if not needed:
Import and Compatibility Issues¶
Issue: _logly.pyd
not found (Windows)¶
Symptoms:
Solutions:
- Install Visual C++ Redistributable:
- Download from: https://aka.ms/vs/17/release/vc_redist.x64.exe
-
Install and restart
-
Check Python architecture matches:
-
Reinstall Logly:
Issue: Module compiled with wrong Python version¶
Symptoms:
Solutions:
-
Ensure Python version matches:
-
Use correct Python interpreter:
-
Rebuild from source (if needed):
File Rotation Issues¶
Issue: Files not rotating¶
Symptoms: - Single log file grows indefinitely - No rotated files created - Rotation policy ignored
Solutions:
-
Verify rotation is configured:
-
Check rotation thresholds:
-
Ensure
logger.complete()
is called: -
Check file permissions for renaming:
Issue: Too many rotated files¶
Symptoms: - Disk filling up with old logs - Hundreds of .log.1
, .log.2
files
Solutions:
-
Set retention policy:
-
Enable compression:
-
Manually clean old files:
Missing or Lost Logs¶
Issue: Logs disappearing¶
Symptoms: - Logs written but file is empty later - Some log messages missing - Intermittent log loss
Solutions:
-
Always call
logger.complete()
: -
Use synchronous writing for critical logs:
-
Check log level filtering:
-
Verify storage_levels configuration:
-
Check disk space:
Issue: Console logs missing¶
Symptoms: - Logs appear in files but not console - Console output incomplete
Solutions:
-
Add console sink explicitly:
-
Check console_levels configuration:
-
Verify stderr/stdout redirection:
Callback Issues¶
Issue: Callbacks not executing¶
Symptoms: - Callback function not called - No callback output
Solutions:
-
Verify callback is added:
-
Check callback function signature:
-
Handle callback exceptions:
Issue: Callback causing errors¶
Symptoms:
Solutions:
-
Add error handling in callback:
-
Test callback independently:
-
Remove problematic callback:
Platform-Specific Issues¶
Windows-Specific¶
Issue: Path separators causing errors
# ✗ Problematic on Windows
logger.add("logs/app.log")
# ✓ Cross-platform compatible
import os
logger.add(os.path.join("logs", "app.log"))
# ✓ Or use forward slashes (works on Windows too)
logger.add("logs/app.log")
Issue: File locks preventing rotation
# Windows locks files more aggressively
# Use date_enabled to create new files instead
logger.add("app.log", rotation="daily", date_enabled=True)
Linux/Mac-Specific¶
Issue: Permission denied in /var/log
# Solution 1: Use user directory
logger.add("~/logs/app.log")
# Solution 2: Create with proper permissions
sudo mkdir /var/log/myapp
sudo chown $USER:$USER /var/log/myapp
logger.add("/var/log/myapp/app.log")
Issue: Signal handling with async writing
import signal
import sys
def signal_handler(sig, frame):
logger.complete() # Flush logs before exit
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
Debugging Tips¶
Enable verbose error messages¶
import logging
import sys
# Enable Python's logging to see internal errors
logging.basicConfig(level=logging.DEBUG)
# Add traceback for exceptions
import traceback
try:
logger.add("problematic.log")
except Exception as e:
traceback.print_exc()
Test minimal configuration¶
# Start with absolute minimum
from logly import logger
logger.add("console")
logger.info("Test message")
logger.complete()
# If this works, add features incrementally
Check file accessibility¶
import os
log_path = "logs/app.log"
# Check if path is writable
try:
os.makedirs(os.path.dirname(log_path), exist_ok=True)
with open(log_path, 'a') as f:
f.write("test\n")
print(f"✓ Path is writable: {log_path}")
except Exception as e:
print(f"✗ Path error: {e}")
Verify Logly version¶
import importlib.metadata
version = importlib.metadata.version('logly')
print(f"Logly version: {version}")
# Check if it's the latest
# Latest version: 0.1.5
Getting Help¶
Before Reporting Issues¶
- Check this troubleshooting guide
- Search existing issues: https://github.com/muhammad-fiaz/logly/issues
- Update to latest version:
pip install --upgrade logly
- Test with minimal example
Reporting Bugs¶
When reporting issues, include:
- Logly version:
pip show logly
- Python version:
python --version
- Operating system: Windows/Linux/Mac + version
- Minimal code example that reproduces the issue
- Full error message and traceback
- Expected vs actual behavior
Report issues at: https://github.com/muhammad-fiaz/logly/issues
Example Bug Report¶
**Logly Version**: 0.1.5
**Python Version**: 3.10.12
**OS**: Windows 11
**Issue**: Logs not writing to file
**Code**:
```python
from logly import logger
logger.add("app.log")
logger.info("Test")
logger.complete()
Expected: Log file created with message Actual: No file created
Error Message: None ```
Common Error Reference¶
Error | Cause | Solution |
---|---|---|
ValueError: Invalid log level | Invalid level string | Use TRACE/DEBUG/INFO/SUCCESS/WARNING/ERROR/CRITICAL |
ValueError: Invalid rotation policy | Invalid rotation format | Use daily/hourly/minutely or size (e.g., "10MB") |
PermissionError | No write access | Use writable directory or fix permissions |
FileNotFoundError | Directory doesn't exist | Create directory with os.makedirs() |
ImportError: No module named 'logly' | Logly not installed | Run pip install logly |
ImportError: DLL load failed | Missing C++ runtime | Install Visual C++ Redistributable |
IOError: File is locked | File in use | Close other programs or use different filename |
RuntimeError: Callback execution error | Callback exception | Add error handling in callback function |
Performance Tuning Checklist¶
- Enable async writing:
async_write=True
- Increase buffer size:
buffer_size=16384
- Reduce flush frequency:
flush_interval=5000
- Filter unnecessary levels:
storage_levels={"DEBUG": False}
- Disable colors if not needed:
color=False
- Use size-based rotation:
rotation="10MB"
- Enable compression:
compression="gzip"
- Set retention policy:
retention=7
- Remove unused sinks: Use
logger.remove(handler_id)
orlogger.reset()
- Minimize callback overhead
Sink Management Issues¶
Issue: Cannot remove sink¶
Symptoms: - remove()
doesn't work - Sink ID not found - Sink still logging after removal
Solutions:
- Save sink ID when adding: ```python from logly import logger
# Save the ID returned by add() sink_id = logger.add("app.log")
# Later, remove using that ID logger.remove(sink_id) ```
- List all sinks to find ID: ```python # Get list of all sink IDs sink_ids = logger.list_sinks() print(f"Active sinks: {sink_ids}")
# Remove specific sink logger.remove(sink_ids[0]) ```
-
Remove all sinks at once:
python # Remove all configured sinks logger.remove_all()
-
Check sink count:
python count = logger.sink_count() print(f"Active sinks: {count}")
Issue: Sink information retrieval fails¶
Symptoms: - sink_info()
returns empty - Cannot get sink details - Sink ID doesn't exist
Solutions:
-
Verify sink exists:
python sink_ids = logger.list_sinks() if sink_id in sink_ids: info = logger.sink_info(sink_id) print(info) else: print(f"Sink {sink_id} not found")
-
Get all sinks information:
python all_info = logger.all_sinks_info() for sink_id, details in all_info.items(): print(f"Sink {sink_id}: {details}")
-
Check sink configuration:
python info = logger.sink_info(sink_id) if info: print(f"Path: {info['path']}") print(f"Rotation: {info['rotation']}") print(f"Async: {info['async_write']}")
File Operations Issues¶
Issue: Cannot read log file¶
Symptoms: - read()
returns empty - read_all()
fails - File exists but cannot be read
Solutions:
- Flush logs before reading: ```python from logly import logger
logger.add("app.log") logger.info("Test message") logger.complete() # Flush all logs
# Now read content = logger.read("app.log") print(content) ```
- Use absolute path: ```python import os
log_path = os.path.abspath("logs/app.log") content = logger.read(log_path) ```
- Check file exists: ```python import os
if os.path.exists("app.log"): content = logger.read("app.log") else: print("Log file not found") ```
- Read all log files:
python # Read all .log files in directory all_logs = logger.read_all("logs/*.log") for filepath, content in all_logs.items(): print(f"\n=== {filepath} ===") print(content)
Issue: Cannot get file metadata¶
Symptoms: - file_metadata()
fails - file_size()
returns 0 - Metadata incomplete
Solutions:
- Ensure file exists and is flushed: ```python logger.complete() # Flush first
metadata = logger.file_metadata("app.log") print(f"Size: {metadata['size']} bytes") print(f"Created: {metadata['created']}") print(f"Modified: {metadata['modified']}") ```
-
Check file size:
python size = logger.file_size("app.log") print(f"File size: {size} bytes")
-
Get line count:
python count = logger.line_count("app.log") print(f"Total lines: {count}")
Issue: Cannot delete log files¶
Symptoms: - delete()
fails - Files not removed - Permission denied when deleting
Solutions:
- Remove sinks before deleting: ```python # Remove all sinks first logger.remove_all()
# Then delete file logger.delete("app.log") ```
-
Delete all log files:
python # Delete all .log files in directory deleted = logger.delete_all("logs/*.log") print(f"Deleted {len(deleted)} files")
-
Handle deletion errors: ```python import os
try: logger.delete("app.log") except PermissionError: # File may be locked logger.remove_all() # Remove sinks logger.delete("app.log") # Try again ```
Context Binding Issues¶
Issue: Context not appearing in logs¶
Symptoms: - bind()
doesn't add context - Extra fields missing - Context not persisted
Solutions:
- Verify bind usage: ```python from logly import logger
# Bind context permanently logger.bind(request_id="abc123", user="john") logger.info("User action") # Output: ... request_id=abc123 user=john ```
-
Use contextualize() for temporary context:
python with logger.contextualize(session_id="xyz"): logger.info("Session started") # session_id only in this block
-
Check JSON format for extra fields:
python logger.configure(json=True) logger.bind(app="myapp", version="1.0") logger.info("Message") # Extra fields visible in JSON output
-
Clear bound context:
python # Reset configuration to clear bindings logger.reset()
JSON Logging Issues¶
Issue: JSON format malformed¶
Symptoms: - Invalid JSON output - Cannot parse log files - Missing fields in JSON
Solutions:
- Enable proper JSON formatting: ```python from logly import logger
logger.configure(json=True, pretty_json=True) logger.info("Test message", extra_field="value") ```
- Read JSON logs properly: ```python import json
# Read and parse JSON logs logs = logger.read_json("app.log", pretty=False) for log in logs: print(json.dumps(log, indent=2)) ```
- Check for NDJSON format:
python # Logly outputs NDJSON (one JSON per line) content = logger.read("app.log") for line in content.strip().split('\n'): log_entry = json.loads(line) print(log_entry)
Advanced Features Troubleshooting¶
Issue: Custom format not applied¶
Symptoms: - Format string ignored - Wrong log structure - Placeholders not replaced
Solutions:
-
Use correct format syntax:
python logger.add( "app.log", format="{time} | {level:8} | {module}:{function} | {message}" )
-
Available placeholders:
python # Valid format placeholders: # {time} - Timestamp # {level} - Log level (e.g., INFO) # {message} - Log message # {module} - Module name # {function} - Function name # {extra} - Extra context fields
-
Verify format is set per-sink:
python # Each sink can have different format logger.add("console", format="{time} {level} {message}") logger.add("file.log", format="{time} | {level:8} | {message}")
Issue: Rotation not working as expected¶
Symptoms: - Files rotate too early/late - Wrong rotation schedule - Size limits not respected
Solutions:
- Check rotation configuration: ```python # Time-based rotation logger.add("app.log", rotation="daily") # Rotates at midnight logger.add("app.log", rotation="hourly") # Every hour
# Size-based rotation logger.add("app.log", rotation="10MB") # At 10MB logger.add("app.log", rotation="1GB") # At 1GB ```
-
Combine with retention:
python logger.add( "app.log", rotation="daily", retention=7 # Keep 7 days )
-
Enable date in filename:
python logger.add( "app.log", rotation="daily", date_enabled=True # Creates app_2025-10-04.log )
Issue: Async write delays logs¶
Symptoms: - Logs appear delayed - Real-time logs not visible - Buffer not flushing
Solutions:
-
Reduce flush interval:
python logger.add( "app.log", async_write=True, flush_interval=100 # Flush every 100ms )
-
Force immediate write:
python # For critical logs, use sync writing logger.add("critical.log", async_write=False)
-
Manual flush:
python logger.info("Important message") logger.complete() # Force flush immediately
-
Reduce buffer size:
python logger.add( "app.log", buffer_size=1024, # Small buffer (1KB) max_buffered_lines=100 # Few lines )
Issue: Callbacks not receiving all logs¶
Symptoms: - Some logs skip callback - Callback executed partially - Missing log levels in callback
Solutions:
- Check callback level filtering: ```python def my_callback(record): # Check what level is received print(f"Level: {record['level']}") print(f"Message: {record['message']}")
logger.add_callback(my_callback) ```
-
Verify callback registration:
python callback_id = logger.add_callback(my_callback) print(f"Callback registered: {callback_id}")
-
Handle all log levels: ```python def universal_callback(record): level = record["level"] message = record["message"] timestamp = record.get("timestamp", "")
# Process all levels if level in ["ERROR", "CRITICAL"]: send_alert(message) elif level == "INFO": log_to_db(message)
logger.add_callback(universal_callback) ```
- Remove and re-add callback:
python logger.remove_callback(callback_id) new_id = logger.add_callback(my_callback)
Still Having Issues?¶
If you've tried the solutions above and still experiencing problems:
- Update Logly:
pip install --upgrade logly
- Check GitHub issues: https://github.com/muhammad-fiaz/logly/issues
- Ask for help: Open a new issue with details
- Contact maintainer: https://github.com/muhammad-fiaz
Documentation: https://muhammad-fiaz.github.io/logly/
GitHub: https://github.com/muhammad-fiaz/logly
PyPI: https://pypi.org/project/logly/
Last Updated: October 4, 2025 - Logly v0.1.5