-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.py
53 lines (42 loc) · 1.6 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import yaml
import logging
import logging.config
import argparse
import filters
import sys
PORT = 57888
LDBPATH = "/p/lname/lname.db"
THREADS = 4
PASSWORD = os.environ.get('PHRAMPU_PASSWORD')
USERNAME = os.environ.get('PHRAMPU_USERNAME')
CALAPIKEY = os.environ.get('PHRAMPU_CALAPIKEY')
MACHINES = yaml.load(open('servers.yaml', 'r'))
MONGODB = 'mongodb://austinschwartz.com:27017/'
LOG_TO_MONGO = True
def configurelogging():
with open('filters.yaml', 'r') as the_file:
config_dict = yaml.load(the_file)
logging.config.dictConfig(config_dict)
configurelogging()
def getargs(logger):
parser = argparse.ArgumentParser(description='Initial settings for the server')
parser.add_argument('-d', '--debug', nargs='?', choices=['DEBUG','INFO','WARNING','ERROR','CRITICAL'],
help='the default debug level for logging')
parser.add_argument('-v', '--verbose', help='Also output logging information to the console', action='store_true')
args = parser.parse_args()
if args.verbose:
ch = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(asctime)s:%(levelname)-7s:%(message)s', '[%m/%d/%Y %H:%M:%S]')
ch.setFormatter(formatter)
ch.addFilter(filters.MyFilter())
logger.addHandler(ch)
if args.debug is not None:
logger.setLevel(args.debug)
def log(*args):
logging.info(*args)
def logerror(e):
logging.error(e)
getargs(logging.getLogger())
LOGFILE = "server.log"
logging.basicConfig(filename=LOGFILE, filemode='w', format='%(asctime)s:%(levelname)s:%(message)s', datefmt='%m/%d/%Y %H:%M:%S', level=logging.DEBUG)