Skip to content
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

Additional logging for setup/debug #90

Closed
nowcodingaway opened this issue Nov 21, 2024 · 1 comment
Closed

Additional logging for setup/debug #90

nowcodingaway opened this issue Nov 21, 2024 · 1 comment

Comments

@nowcodingaway
Copy link

nowcodingaway commented Nov 21, 2024

In case it is of any help or inspiration to others, I am sharing what I have done to assist with checking that the CRONS are running as expected and to be able to unpick errors if anything stops working.

I also share this in case it helps drive any improvements to the logging system or the readme/setup instructions.

I could not tell if this was already being logged anywhere, please let me know if what I have done is redundant.

Here is what I have done.

in example.py I included:
from datetime import datetime
At the top

I then added additional logging after around line 16:

current_date = datetime.now().strftime("%Y-%m-%d")
logging.basicConfig(filename='/home/admin/Renogy/logs/' + current_date + '-runlog-' + config_file + '.log',
                    filemode='a',
                    format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
                    datefmt='%H:%M:%S',
                    level=logging.INFO)
                    
logging.info("Renogy Started Logging With Config " + config_file)

I created a 'logs' folder in the same location as the project files.

Now as the script gets called from my cron, it will create a log for today, and it will do it per instance. So for example, I have one cron loading the battery config and another loading the controller config. I will end up with a log for each of those.

Each time a new day arrives, a new log file will be created for each of them.

Screenshot 2024-11-21 at 10 29 06 am

I am running a Pi 5, and the python scripts are running in a venv / virtual environment. For anyone that is interested, this is how my working cron lines ended up

*/1 * * * *  /home/admin/Renogy/venv/bin/python /home/admin/Renogy/example.py controller-config.ini #runs every 1 mins
*/1 * * * * /home/admin/Renogy/venv/bin/python /home/admin/Renogy/example.py battery-config.ini #runs every 1 mins

I will likely set up another cron to clean out old log files that are 30 days old at some point.

Once I know that everything is running well for a while, I will likely change down the logging to just capture errors, and potentially send a notification somewhere.

I am a beginner at best so this is me muddling my way through. I find that having more logs and information helps me better understand how things are working and resolve problems, but right now I am also learning the logging system and approaches themselves. So please don't judge me too harshly :)

p.s wasn't sure if this should be in 'issues' or 'discussions' - apologies if this is incorrectly submitted, and do let me know the correct approach moving forward.

@nowcodingaway
Copy link
Author

nowcodingaway commented Nov 21, 2024

I now realise that if you are using polling, CRON is likely not the right way to go about this, and rather, systemd / running the commands once at startup might be better.

I saw the issue #77 (systemd example) but face the same challenge of how to pass the flag, and ultimately start 2 services. One for CTRL and one for BATT.

EDIT:
I have now added my solution / what is working for me using systemd over on issue #77

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant