Skip to content

Commit

Permalink
Ensure logs path exists when initializing logs
Browse files Browse the repository at this point in the history
Otherwise, for example, if we start datastore alone
like we do in the tests, we try to create logs without
the directory and traceback.
  • Loading branch information
dnarvaez committed Oct 7, 2013
1 parent 2d33c92 commit cf39273
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/sugar3/logger.py
Expand Up @@ -118,6 +118,13 @@ def cleanup():


def start(log_filename=None):
logs_path = env.get_logs_path()

try:
os.makedirs(logs_path)
except OSError:
pass

# remove existing handlers, or logging.basicConfig() won't have no effect.
root_logger = logging.getLogger('')
for handler in root_logger.handlers:
Expand Down Expand Up @@ -156,7 +163,7 @@ def flush(self):

if log_filename:
try:
log_path = os.path.join(get_logs_dir(), log_filename + '.log')
log_path = os.path.join(logs_path, log_filename + '.log')

log_fd = os.open(log_path, os.O_WRONLY | os.O_CREAT)
os.dup2(log_fd, sys.stdout.fileno())
Expand Down

0 comments on commit cf39273

Please sign in to comment.