icloud-photos-downloader / icloud_photos_downloader

A command-line tool to download photos from iCloud
MIT License
6.8k stars 554 forks source link

Log level options #123

Open ifoss-me opened 5 years ago

ifoss-me commented 5 years ago

It looks like, though the documentation for icloudpd on GitHub suggest that there's an "error" option for log-level, that it doesn't function and instead outputs debug and info messages as well.

Being a novice coder at best, I'm not quite sure, but when poking around icloud_photos_downloader/icloudpd/logger.py, it looks like there's actually no "error" option.

Could that be causing my problem? If so, should/can that option be added?

koldinger commented 5 years ago

I ran into this same issue. The problem appears to be that each module gets it's own logger, but the log-level option only sets the log level in the logger used in base.py. As a result, that logger logs at the correct level, but the other modules all don't have the value set correctly.

I have a quick hack level fix that returns the same logger to all the modules, so the logging level is set correctly universally. It's a hack, but it does the trick.

Kryptonit3-zz commented 4 years ago

@koldinger what is your fix? I am making a cronjob that will email output. Don't want it being 15 thousand lines long. Only want to see errors. Thanks!

----- edit -----

I decided to make a script that outputs to a log file and then I remove all lines that contain "already exists" and then it sends me an email once a day. Here is what I have for those wondering. You must already have a mail client setup to send outbound mail. I used exim4.

Here are 2 sites that helped me with setting up exim4 http://www.manu-j.com/blog/wordpress-exim4-ubuntu-gmail-smtp/75/ https://www.fyzix.net/index.php?title=Installing_and_Configuring_Exim4_for_Gmail_SMTP_Relay If using Gmail, generate an app specific password, no need to make your account less secure by changing security to Allow less secure apps: ON. https://myaccount.google.com/apppasswords (Other custom name)

Script installed at /opt/icloud_photos_downloader My custom script directory at /opt/icloud_photos_downloader_scripts

/opt/icloud_photos_downloader_scripts/cron_jesse.sh contents

#!/usr/bin/env bash

# start a timer
start=$(date +%s);

# clear previous run from log file
sudo cp /dev/null /opt/icloud_photos_downloader_scripts/backup_jesse.log

# run script to grab all photos/videos and output to log file
sudo python /opt/icloud_photos_downloader/icloudpd.py --username icloudusername@gmail.com --password icloudpassword --directory /mnt/media/icloud_backups/jesse/ --size original --live-photo-size original --smtp-host smtp.gmail.com --smtp-port 587 --smtp-username myemail@gmail.com --smtp-password mypassword --notification-email myemail@gmail.com --no-progress-bar --log-level error > /opt/icloud_photos_downloader_scripts/backup_jesse.log

# remove the lines that output a file already exists so we only see what new files were added
sudo sed -i "/\b\(already exists\)\b/d" /opt/icloud_photos_downloader_scripts/backup_jesse.log

# stop timer and calculate runtime
end=$(date +%s);
runtime=$((end-start));
hours=$((runtime / 3600));
minutes=$(( (runtime % 3600) / 60 ));
seconds=$(( (runtime % 3600) % 60 ));
duration="Runtime: $hours:$minutes:$seconds (hh:mm:ss)"

# prepend the log file with the runtime so we see it first in the email
sudo sed -i "1s;^;$duration\n;" /opt/icloud_photos_downloader_scripts/backup_jesse.log

# send the email
sudo mail -s 'iCloud Backup Report - Jesse' myemail@gmail.com < /opt/icloud_photos_downloader_scripts/backup_jesse.log

crontab contents - will run once a day at midnight 0 0 * * * /opt/icloud_photos_downloader_scripts/cron_jesse.sh

menkej commented 3 years ago

Currently the script is not logging "ERRORS" in any separate way. What exactly would be your expectation which messages should come out an which not? Maybe we could put something together? Or are you already happy with @Kryptonit3-zz 's script solution?