Skip to content

Commit 5249efe

Browse files
authored
Merge pull request #220 from ComputerScienceHouse/wdn/exception
log exceptions instead of printing them in starrs.py
2 parents 0c2512c + 525a01f commit 5249efe

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

proxstar/starrs.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import logging
2+
3+
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
4+
5+
16
def get_next_ip(starrs, range_name):
27
c = starrs.cursor()
38
try:
@@ -7,7 +12,7 @@ def get_next_ip(starrs, range_name):
712
results = c.fetchall()
813
c.execute('COMMIT')
914
except Exception as e:
10-
print(e)
15+
logging.exception(e)
1116
starrs.rollback()
1217
finally:
1318
c.close()
@@ -23,7 +28,7 @@ def get_ip_for_mac(starrs, mac):
2328
results = c.fetchall()
2429
c.execute('COMMIT')
2530
except Exception as e:
26-
print(e)
31+
logging.exception(e)
2732
starrs.rollback()
2833
finally:
2934
c.close()
@@ -41,7 +46,7 @@ def renew_ip(starrs, addr):
4146
results = c.fetchall()
4247
c.execute('COMMIT')
4348
except Exception as e:
44-
print(e)
49+
logging.exception(e)
4550
starrs.rollback()
4651
finally:
4752
c.close()
@@ -79,7 +84,7 @@ def check_hostname(starrs, hostname):
7984
available = False
8085
c.execute('COMMIT')
8186
except Exception as e:
82-
print(e)
87+
logging.exception(e)
8388
valid = False
8489
available = False
8590
starrs.rollback()
@@ -104,7 +109,7 @@ def register_starrs(starrs, name, owner, mac, addr):
104109
c.callproc('api.modify_system', (name, 'comment', f'Owned by {owner}'))
105110
c.execute('COMMIT')
106111
except Exception as e:
107-
print(e)
112+
logging.exception(e)
108113
starrs.rollback()
109114
finally:
110115
c.close()
@@ -120,7 +125,7 @@ def delete_starrs(starrs, name):
120125
results = c.fetchall()
121126
c.execute('COMMIT')
122127
except Exception as e:
123-
print(e)
128+
logging.exception(e)
124129
starrs.rollback()
125130
finally:
126131
c.close()

0 commit comments

Comments
 (0)