Skip to content

Commit

Permalink
Logs are now written for individual runs
Browse files Browse the repository at this point in the history
Log files are generated containing the date and time of the run and are
stored in the `logs/` directory.
  • Loading branch information
jamestaylr committed May 16, 2015
1 parent ddd2bf2 commit 7214bb8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
debug: True
# when changing the port name, make sure to also change the port in the client
port: 8888
log_name: sailbot.log
transmission_delay: 5
eval_delay: 5

Expand Down
6 changes: 3 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
boundary_locations = []

# Specifies the default values
values = {'debug': False, 'port': 8888, 'log_name': 'sailbot.log',
'transmission_delay': 5, 'eval_delay': 5, 'current_desired_heading': 0,
values = {'debug': False, 'port': 8888, 'transmission_delay': 5, 'eval_delay': 5, 'current_desired_heading': 0,
'direction': 0, 'absolute_wind_direction': 0, 'max_turn_rate_angle': 70, 'max_rudder_angle': 30}

## ----------------------------------------------------------
Expand Down Expand Up @@ -44,7 +43,7 @@ def __init__(self, *args, **kwargs):
logging.critical("Could not connect to servo socket")


# set up logging
# Set up logging to the web server console
logging.getLogger().addHandler(modules.log.WebSocketLogger(self))

def set_rudder_angle(self, angle):
Expand Down Expand Up @@ -196,6 +195,7 @@ def sailable(self, target_location):
try:
threading.current_thread().setName('Main')

# Sets up the program configuration
modules.utils.setup_config(values)
modules.utils.setup_locations(target_locations, boundary_locations)

Expand Down
21 changes: 10 additions & 11 deletions src/modules/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python
import json, logging, configparser, modules.calc
import json, logging, configparser, modules.calc, time, os
from modules.location import Location
from datetime import datetime

Expand Down Expand Up @@ -34,7 +34,7 @@ def setup_locations(target_locations, boundary_locations):

def setup_config(values):

# logging in this method must stay as print statements because the logger
# Logging in this method must stay as print statements because the logger
# has not been defined yet

try:
Expand All @@ -43,29 +43,28 @@ def setup_config(values):

values['debug'] = config.getboolean('DEFAULT', 'debug')
values['port'] = config.getint('DEFAULT', 'port')
values['log_name'] = config.get('DEFAULT', 'log_name')
values['transmission_delay'] = config.get('DEFAULT', 'transmission_delay')
values['eval_delay'] = config.get('DEFAULT', 'eval_delay')

modules.calc.point_proximity_radius = config.get('LOGIC',
'point_proximity_radius')
modules.calc.point_proximity_radius = config.get('LOGIC', 'point_proximity_radius')

print('Configuration file successfully loaded.')

except configparser.NoOptionError:
print('The locations configuration file could not be found or is malformed!')

if values['debug']:
log_format = \
'[%(asctime)s] %(threadName)-7s %(levelname)-0s: %(message)s'
log_format = '[%(asctime)s] %(threadName)-7s %(levelname)-0s: %(message)s'

log_path = r'logs/'
if not os.path.exists(log_path): os.makedirs(log_path)

logging.basicConfig(filename=values['log_name'], format=log_format,
logging.basicConfig(filename='logs/' + time.strftime("%Y-%m-%d %H-%M-%S") + '.log', format=log_format,
datefmt='%H:%M:%S', level=logging.DEBUG)

root = logging.StreamHandler()
root.setFormatter(logging.Formatter(log_format, '%H:%M:%S'))

logging.getLogger().addHandler(root)

logging.info('-------------------------------')
logging.info('Log started on: %s'
% datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
logging.info('Log started on: %s' % datetime.now().strftime('%Y-%m-%d %H:%M:%S'))

0 comments on commit 7214bb8

Please sign in to comment.