Skip to content

Commit

Permalink
Merge pull request #14 from mietzen/fix-docker-logging
Browse files Browse the repository at this point in the history
fixed docker logging
  • Loading branch information
mietzen authored Jul 29, 2023
2 parents 4075d0e + 32d7f8a commit e2e035b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ services:
# SLEEP: "300" # Seconds to sleep between DynDNS runs
# IPV4_ONLY: "FALSE" # Only set IPv4 address
# IPV6_ONLY: "FALSE" # Only set IPv6 address
PYTHONUNBUFFERED: 1 # sent stdout and stderr straight to the terminal
# DEBUG: "FALSE" # DEBUG LOGGING
restart: unless-stopped
28 changes: 19 additions & 9 deletions Docker/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import os
import sys
import logging
from time import sleep
from porkbun_ddns import PorkbunDDNS, cli

logger = logging.getLogger('porkbun_ddns')
logger.setLevel(logging.INFO)
logger.propagate = False

sleep_time = int(os.getenv('SLEEP', 300))
domain = os.getenv('DOMAIN', None)

Expand All @@ -22,27 +27,32 @@
if os.getenv('IPV6_ONLY', 'False').lower() in ('true', '1', 't'):
ipv4 = False

if os.getenv('DEBUG', 'False').lower() in ('true', '1', 't'):
logger.setLevel(logging.DEBUG)
for handler in logger.handlers:
handler.setLevel(logging.DEBUG)

if os.getenv('INTEGRATION_TEST'):
print('\n------------------------------------')
print('INTEGRATION TEST! Printing help menu')
print('------------------------------------\n')
logger.info('\n------------------------------------')
logger.info('INTEGRATION TEST! logger.infoing help menu')
logger.info('------------------------------------\n')
while True:
try:
cli.main(argv=['-h'])
except SystemExit:
pass
finally:
print('\n------------------------------------')
print('Sleeping... {}s'.format(sleep_time))
print('------------------------------------\n')
logger.info('\n------------------------------------')
logger.info('Sleeping... {}s'.format(sleep_time))
logger.info('------------------------------------\n')
sleep(sleep_time)

if not all([os.getenv('DOMAIN'), os.getenv('SECRETAPIKEY'), os.getenv('APIKEY')]):
print('Please set DOMAIN, SECRETAPIKEY and APIKEY')
logger.info('Please set DOMAIN, SECRETAPIKEY and APIKEY')
sys.exit(1)

if not any([ipv4, ipv6]):
print('You can not set both IPV4_ONLY and IPV6_ONLY to TRUE')
logger.info('You can not set both IPV4_ONLY and IPV6_ONLY to TRUE')
sys.exit(1)

porkbun_ddns = PorkbunDDNS(config, domain, public_ips=public_ips,
Expand All @@ -56,5 +66,5 @@
porkbun_ddns.update_records()
else:
porkbun_ddns.update_records()
print('Sleeping... {}s'.format(sleep_time))
logger.info('Sleeping... {}s'.format(sleep_time))
sleep(sleep_time)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ services:
# SLEEP: "300" # Seconds to sleep between DynDNS runs
# IPV4_ONLY: "FALSE" # Only set IPv4 address
# IPV6_ONLY: "FALSE" # Only set IPv6 address
PYTHONUNBUFFERED: 1 # sent stdout and stderr straight to the terminal
# DEBUG: "FALSE" # DEBUG LOGGING
restart: unless-stopped
```
Expand Down

0 comments on commit e2e035b

Please sign in to comment.