1 #!/usr/local/bin/python3 |
1 #!/usr/local/bin/python3 |
2 |
2 |
3 import logging |
3 import logging |
4 from threading import Thread |
4 from fifolog import FIFOHandler |
5 |
5 |
6 logging.basicConfig(#filename='example.log', |
6 # |
7 #format='%(levelname)s:%(message)s', |
7 # Branding |
8 level=logging.DEBUG) |
8 # |
|
9 appname="borgend" |
|
10 appname_stylised="Borgend" |
9 |
11 |
10 logger=logging.getLogger(__name__) |
12 # |
|
13 # Logging configuration |
|
14 # |
11 |
15 |
12 from backup import Backup |
16 loglevel=logging.DEBUG |
13 from config import settings |
17 logfmt="%(asctime)s:%(levelname)s:%(name)s:%(message)s" |
14 from queue import Queue |
18 fifolog_capacity=1000 |
15 from ui import BorgendTray |
19 fifolog_level=logging.WARNING |
16 import signal, os |
20 fifolog_fmt="%(asctime)s:%(levelname)s:%(message)s" |
17 |
21 |
18 backupconfigs=settings['backups'] |
22 # |
19 backups=[None]*len(backupconfigs); |
23 # Setup logger |
|
24 # |
20 |
25 |
21 for i in range(len(backupconfigs)): |
26 logger=logging.getLogger(appname) |
22 logger.info('Setting up backup set %d' % i) |
27 logger.setLevel(loglevel) |
23 backups[i]=Backup(i, backupconfigs[i]) |
28 logger.propagate=True |
24 backups[i].schedule() |
29 fifolog=FIFOHandler(fifolog_capacity) |
|
30 logger.addHandler(fifolog) |
|
31 fifolog.setLevel(fifolog_level) |
|
32 fifolog.setFormatter(logging.Formatter(fifolog_fmt)) |
25 |
33 |
26 if __name__ == "__main__": |
34 if __name__=="__main__": |
27 #print(settings) |
35 |
|
36 import logging.handlers |
|
37 import os |
|
38 import config |
|
39 |
|
40 if not os.path.isdir(config.logs_dir): |
|
41 os.makedirs(config.logs_dir) |
|
42 |
|
43 handler=logging.handlers.TimedRotatingFileHandler( |
|
44 os.path.join(config.logs_dir, appname+'.log'), |
|
45 when='D', interval=1) |
|
46 handler.setFormatter(logging.Formatter(logfmt)) |
|
47 logger.addHandler(handler) |
|
48 |
|
49 from threading import Thread |
|
50 from backup import Backup |
|
51 from queue import Queue |
|
52 from ui import BorgendTray |
|
53 import signal, os |
|
54 |
|
55 backupconfigs=config.settings['backups'] |
|
56 backups=[None]*len(backupconfigs); |
|
57 |
|
58 for i in range(len(backupconfigs)): |
|
59 logger.info('Setting up backup set %d' % i) |
|
60 backups[i]=Backup(i, backupconfigs[i]) |
|
61 backups[i].schedule() |
|
62 |
28 tray=BorgendTray(backups); |
63 tray=BorgendTray(backups); |
29 tray.run() |
64 tray.run() |
30 pass |
|
31 |
65 |
32 # |
66 # |
33 # This shit is fucked, disables ^C etc., and threading doesn't seem to help |
67 # This shit is fucked, disables ^C etc., and threading doesn't seem to help |
34 # |
68 # |
35 |
69 |