This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

Add log rotation and update README for logging configuration

+23 -5
+3 -3
README.md
··· 91 91 - Authenticate using the AT Protocol. 92 92 - Update the Bluesky avatar accordingly. 93 93 94 - Execution logs will be displayed directly in the console. 94 + Execution logs will be displayed directly in the console, and a log file will be created in the `~/logs/bluesky-avatar-updater` directory. The log file will rotate when it reaches 10 MB, keeping up to 5 backup log files, each named with a timestamp for each execution. 95 95 96 96 ## Automating with Cron (Linux) 97 97 ··· 120 120 2. Add the following line to run the script every hour at the top of the hour: 121 121 122 122 ```bash 123 - 0 * * * * /path/to/your/venv/bin/python3 /path/to/bluesky-avatar-updater/src/main.py 123 + 0 * * * * /path/to/your/.venv/bin/python3 /path/to/bluesky-avatar-updater/src/main.py 124 124 ``` 125 125 126 - Replace `/path/to/your/venv/bin/python3` with the path to your virtual environment's Python interpreter and `/path/to/bluesky-avatar-updater/src/main.py` with the full path to the `main.py` script. 126 + Replace `/path/to/your/.venv/bin/python3` with the path to your virtual environment's Python interpreter and `/path/to/bluesky-avatar-updater/src/main.py` with the full path to the `main.py` script. 127 127 128 128 ## Troubleshooting 129 129
+20 -2
src/main.py
··· 9 9 from atproto.exceptions import BadRequestError 10 10 import sys 11 11 from crontab import CronTab 12 + from logging.handlers import RotatingFileHandler 12 13 13 14 # Ensure the script is run inside a virtual environment 14 15 if not hasattr(sys, 'real_prefix') and not (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix): ··· 24 25 JSON_PATH = os.path.join(ASSETS_DIR, "cids.json") 25 26 SCRIPT_PATH = os.path.abspath(__file__) 26 27 27 - # Configure basic console logging 28 + # Define the log file directory and log file path 29 + log_dir = os.path.expanduser("~/logs/bluesky-avatar-updater") 30 + if not os.path.exists(log_dir): 31 + os.makedirs(log_dir) 32 + 33 + # Log file with datetime stamp, but will be rotated 34 + log_file_path = os.path.join(log_dir, f"avatar_update_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log") 35 + 36 + # Configure logging to both console and file with rotation 28 37 console_handler = logging.StreamHandler() 29 38 console_handler.setLevel(logging.INFO) # Show only INFO and higher levels on console 39 + 40 + # Create a rotating file handler (max file size 10 MB, backup 5 old log files) 41 + file_handler = RotatingFileHandler( 42 + log_file_path, maxBytes=10 * 1024 * 1024, backupCount=5 43 + ) 44 + file_handler.setLevel(logging.INFO) # Save all logs to file 45 + 30 46 formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") 31 47 console_handler.setFormatter(formatter) 48 + file_handler.setFormatter(formatter) 32 49 33 50 # Root logger setup 34 51 logger = logging.getLogger() ··· 38 55 for handler in logger.handlers[:]: 39 56 logger.removeHandler(handler) 40 57 41 - # Add the custom console handler 58 + # Add the custom handlers 42 59 logger.addHandler(console_handler) 60 + logger.addHandler(file_handler) 43 61 44 62 # Suppress httpx logging (this stops httpx internal logs) 45 63 logging.getLogger("httpx").setLevel(logging.WARNING) # Suppress INFO and DEBUG logs from httpx